Top Banner
Java - Ireport UserLinuxPlug : Hervert Navarro Vela - 1 - [email protected] 1 Instalación y Configuración de Ireport 2 3 Prerrequisitos: 4 5 apache-ant-1.6.5-bin.zip. 6 iReport-1.2.5-windows-installer. 7 8 9 Instalación de apache-ant-1.6.5-bin: 10 11 1. Crear un directorio con el nombre ANT_HOME en el directorio raiz C:\ 12 2. Descomprime el archivo apache-ant-1.6.5-bin.zip. en la carpeta creada. 13 14 15 16 3. Configurar las variables de entorno. 17 18 a. Click derecho al icono Mi Pc , luego seleccionar Propiedades. 19 b. Opciones Avanzadas / Variables de Entorno. 20 21 22 23 24 25 26 27 c. Modificar : Path = ………………………………;C:\ANT_HOME\bin 28 29 30 1 2 3
18
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 1 - [email protected]

1 Instalación y Configuración de Ireport 2 3 Prerrequisitos: 4 5

apache-ant-1.6.5-bin.zip. 6 iReport-1.2.5-windows-installer. 7 8 9

Instalación de apache-ant-1.6.5-bin: 10 11

1. Crear un directorio con el nombre ANT_HOME en el directorio raiz C:\ 12 2. Descomprime el archivo apache-ant-1.6.5-bin.zip. en la carpeta creada. 13 14

15 16

3. Configurar las variables de entorno. 17 18

a. Click derecho al icono Mi Pc , luego seleccionar Propiedades. 19 b. Opciones Avanzadas / Variables de Entorno. 20 21

22 23

24 25 26

27 c. Modificar : Path = ………………………………;C:\ANT_HOME\bin 28

29 30

1

2

3

Page 2: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 2 - [email protected]

31 32 Instalación del Ireport: 33 34

1. Abrir el archivo : iReport-1.2.5-windows-installer. 35 36

37

38

39 40

41 42 43

2. La interfaz grafica de IReport comienza a cargarse: 44 45

1

2

3

4

5

6

7

8

Page 3: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 3 - [email protected]

46 47

48 49

3. Configurar las opciones : Options / Settings….. 50 51

52 53

54 55

Page 4: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 4 - [email protected]

56

57 58

59 60 61 62 63 64 65

Page 5: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 5 - [email protected]

66 4. Crear un Documento: 67 68

Fichero / Nuevo Documento 69 70

71 72 73

74

75 76 77 78 79 80 81 82 83 84

Page 6: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 6 - [email protected]

Donde: 85

86 87 5. Para usar texto puro usar: 88

89

90 91

6. Para usar campos usar : 92 93

94 95

7. Para usar imágenes usar: 96

97 98

8. Conexión con la Base de Datos: 99 100 Data / Conexiones/Fuente de Datos 101 102

103 104

Page 7: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 7 - [email protected]

105 106 Click en Test : 107 108

109 Luego click en Save : 110 Se mostrara la sgte. Pantalla: 111 112

113 114

Page 8: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 8 - [email protected]

9. Agregar nuestros campos de la Base de Datos: 115 116

117 118 119 120 121

122 123 124

125 Observación : En la clave PIN ingresar sa 126 127

128 129 Luego Click en el Botón Ok. Aparecerá la siguiente ventana: 130 131

132 133 134 135 136 137 138 139 140 141

Doble Click Se Muestra

Page 9: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 9 - [email protected]

142 10. Diseñar el siguiente Reporte: 143 144

145 146 147 148 11. Agregar un parámetro: 149 150

151 152 153

154 155

Parametro

Campo

Doble Click

Page 10: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 10 - [email protected]

156 157 158

12. Compilar: 159 160

Construir / Compilar 161 162 Luego ingresar el nombre del Reporte : Reporte_Clientes.jrxml 163 164

165 166 167

Nota : Observar el siguiente mensaje. 168 169

170 171

Page 11: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 11 - [email protected]

172 13. Ejecutar Informe: 173

174 Construir / Ejecutar Informe 175

176

177 178

179 180 181 182

183 184 185 186 187

Page 12: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 12 - [email protected]

188 Ejecutar un Reporte a usando de Java- Eclipse. 189 190

1. Copie las librerías de la siguiente ruta : C:\Archivos de programa\JasperSoft\iReport-1.2.5\lib 191 192

193 194 195

Hacia el directorio : C:\j2sdk1.4.2_07\jre\lib\ext 196 197

198 199 200 201 202 203

Page 13: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 13 - [email protected]

204 2. Luego copie las librerias .jar en el proyecto de Eclipse (Dentro del Paquete): 205

a. Clic Derecho sobre el paquete y luego Paste. 206 207

208 209

210 b. Configure la Librerías copiadas: 211 212

213 214 215 216 217

218

Page 14: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 14 - [email protected]

c. 219 220

221 222

d. 223 224

225 226 227

Page 15: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 15 - [email protected]

228 229 230

231 232 233

Page 16: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 16 - [email protected]

234 Crear un JFrame en Eclipse que permita mostrar el Reporte Creado. 235 236 237 [FrameReporteClientes.java] 238 239

240 241 242 243 package sistema_ventas; 244 245 import java.util.*; 246 import javax.swing.*; 247 import java.sql.Connection; 248 import java.awt.event.*; 249 250 /*Librerías necesarias para Jasper Reports*/ 251 import net.sf.jasperreports.engine.*; 252 import net.sf.jasperreports.view.*; 253 254 255 public class FrameReporteClientes { 256 257 private JFrame ventanaPrincipal; 258 259 public static void main(String[] args) { 260

new FrameReporteClientes(); 261 } 262 263 public FrameReporteClientes() 264 { 265 // Construcción de la ventana principal 266 ventanaPrincipal = new JFrame("+++Hervert Navarro Vela +++"); 267 JButton boton = new JButton("Reporte de Clientes"); 268 ventanaPrincipal.getContentPane().add(boton); 269 ventanaPrincipal.pack(); 270 271 // Hacer que el botón abra la el Archivo JasperReport. 272 //public static Statement ejecutar2,ejecutar3; 273 274 boton.addActionListener(new ActionListener() { 275 public void actionPerformed(ActionEvent e) { 276 //------------------- 277 try{ 278 //Ruta del Archivo Jasper 279 String ruta="C:\\Reporte_Clientes.jasper"; 280 281 //Conectar a sqlserver 282 moduloConexion.servidor="(local)"; 283 moduloConexion.bd="sisVentas_HNV"; 284 moduloConexion.usuario=""; 285 moduloConexion.clave=""; 286 moduloConexion.conectar(); 287 288 289 Map parameters = new HashMap(); 290 parameters.put("nom","[email protected]"); 291 System.out.print(ruta); 292 //Preparación del Reporte ( en esta etapa llena el diseño del reporte) 293 //Reporte diseñado y compilado con Ireport 294 295 JasperPrint imprimir = JasperFillManager.fillReport(ruta,parameters,moduloConexion.cn); 296 297 JasperViewer visor = new JasperViewer(imprimir,false); 298 visor.show(); 299 300 }catch(Exception msg) 301 { 302 JOptionPane.showMessageDialog(null,msg.getMessage()); 303 } 304 finally{ 305

} 306

Page 17: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 17 - [email protected]

} 307 }); 308 309 310 // Mostrar la ventana principal 311 ventanaPrincipal.setSize(300,60); 312 ventanaPrincipal.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 313 ventanaPrincipal.setVisible(true); 314 ventanaPrincipal.setLocationRelativeTo(null); 315 316 } 317 318 } 319 320

321

[moduloConexion.java] 322

323

package sistema_ventas; 324 325 import java.sql.*; 326 import javax.swing.*; 327 328 public class moduloConexion { 329 public static Connection cn; 330 public static Statement comando; 331 public static String servidor,bd,usuario,clave; 332 private static ResultSet datos; 333 private static Statement creardatos; 334 335 public moduloConexion() 336 { 337 //Constructor 338 } 339 340 //------------SqlServer------------------------------- 341 342 public static Connection conectar(){ 343 try{ 344 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 345 cn = DriverManager.getConnection("Jdbc:Odbc:Driver={SQL Server}; " + 346 "Server=" + servidor + ";" + 347 "Database="+ bd +";" + 348 "Uid="+ usuario +";Pwd=" + clave); 349 350 }catch(ClassNotFoundException ex1){ 351 JOptionPane.showMessageDialog(null,"Error en Controlador: " + ex1.getMessage()); 352 }catch(SQLException msg){ 353 JOptionPane.showMessageDialog(null,"Error SQL: " + msg.getMessage()); 354 } 355 356 return cn; 357 } 358 //---------Mysql Server------------------ 359 360 public static Connection conectarMysql(){ 361 try{ 362 Class.forName("com.mysql.jdbc.Driver"); 363 cn = DriverManager.getConnection("jdbc:mysql://"+ servidor + "/" + bd, 364 usuario,clave); 365 366 }catch(ClassNotFoundException ex1){ 367 JOptionPane.showMessageDialog(null,"Error en Controlador: " + ex1.getMessage()); 368 }catch(SQLException msg){ 369 JOptionPane.showMessageDialog(null,"Error SQL: " + msg.getMessage()); 370 } 371 return cn; 372 } 373 374 public static ResultSet mostrar(String cadsql) 375 { 376 try{ 377 378 creardatos = cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); 379 datos= creardatos.executeQuery(cadsql); 380 381 }catch(Exception ex){ 382 JOptionPane.showMessageDialog(null,"Error SQL: " + ex.getMessage()); 383 } 384 385 return datos; 386 } 387 388 389 390

Page 18: MANUAL POO

Java - Ireport

UserLinuxPlug : Hervert Navarro Vela - 18 - [email protected]

public static String ejecutar(String cadsql,String msg) 391 { 392 try{ 393 394 comando = cn.createStatement(); 395 comando.executeQuery(cadsql); 396 397 }catch(Exception ex){ 398 JOptionPane.showMessageDialog(null,"Error SQL: " + ex.getMessage()); 399 } 400 401 return msg; 402 } 403 } 404

405 406

407 408 409 410 411