public class Reporte extends javax.swing.JFrame {
/** Creates new form Reporte */Pero me da el sqte error
public Reporte() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
cmdImprimir = new javax.swing.JButton();
txtParam = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
cmdImprimir.setText("Reporte");
cmdImprimir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdImprimirActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(148, 148, 148)
.addComponent(cmdImprimir))
.addGroup(layout.createSequentialGroup()
.addGap(82, 82, 82)
.addComponent(txtParam, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(101, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(90, 90, 90)
.addComponent(cmdImprimir)
.addGap(18, 18, 18)
.addComponent(txtParam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(149, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void cmdImprimirActionPerformed(java.awt.event.ActionEv ent evt) {
try
{
//Ruta de Archivo Jasper
String fileName="D:\\Mis Documentos\\POSSUMUS\\Ejemplos jasperreport\\banco1.jasper";
//Ruta de archivo pdf de destino
String destFileNamePdf="C:\\rep_cli.pdf";
//Ruta de archivo xls de destino
String destFileNameXls="C:\\rep_cli.xls";
//Pasamos parametros al reporte Jasper.
Map parameters = new HashMap();
parameters.put("P_bco_Codigo",txtParam.getText());
//Preparacion del reporte (en esta etapa se inserta el valor del query en el reporte).
JasperPrint jasperPrint=JasperFillManager.fillReport(fileName, parameters, getConnection());
//Creación del PDF
JasperExportManager.exportReportToPdfFile(jasperPr int, destFileNamePdf);
//Creación del XLS
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_P RINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_F ILE_NAME, destFileNameXls);
exporter.setParameter(JRXlsExporterParameter.IS_ON E_PAGE_PER_SHEET, Boolean.TRUE);
exporter.exportReport();
System.exit(0);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Reporte().setVisible(true);
}
});
}
private static Connection getConnection() throws ClassNotFoundException, SQLException {
//Configuración de la conexión.
String driver = "com.mysql.jdbc.Driver";
String connectString = "jdbc:mysql://localhost:3306/logistica";
String user = "root";
String password = "root";
Class.forName(driver);
Connection conn = DriverManager.getConnection(connectString, user, password);
//Retornamos la conexión establecida.
return conn;
}
// Variables declaration - do not modify
private javax.swing.JButton cmdImprimir;
private javax.swing.JTextField txtParam;
// End of variables declaration
}
warning: [path] bad path element "D:\Download\JasperReports\jasperreports-1.3.1\lib\log4j-core.jar": no such file or directory
Garcias