I'm trying to do some reports in jasper, but I have some difficulties to do it, can you help me?
I downloaded from
http://jasperreports.sourceforge.net/
jasperreports-0.6.5.jar
jasperreports-0.6.5-applet.jar
and I copied them in this path:
C:\j2sdk1.4.2_07\jre\lib\ext
After that I generated an simple report and compile with iReport 0.4.1
C:\reports\rep_cli.jasper
Then I created a project in NetBeans 4 to execute my report, this is the code:
Code
package reportload;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.export.*;
import net.sf.jasperreports.engine.util.*;
import net.sf.jasperreports.view.*;
import java.sql.*;
import java.io.*;
import java.util.*;
public class Main {
public Main() {
}
public static void main(String[] args) {
try
{
String fileName="C:\\reports\\rep_cli.jasper";
String destFileNamePdf="C:\\reports\\rep_cli.pdf";
String destFileNameXls="C:\\reports\\rep_cli.xls";
Map parameters = new HashMap();
parameters.put("sql_query", new String("select * from clients"));
JasperPrint jasperPrint=JasperFillManager.fillReport(fileName, parameters, getConnection());
JasperExportManager.exportReportToPdfFile(jasperPrint, destFileNamePdf);
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFileNameXls);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
exporter.exportReport();
System.exit(0);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
private static Connection getConnection() throws ClassNotFoundException, SQLException {
//Configuración de la conexión.
String driver = "org.postgresql.Driver";
String connectString = "jdbc:postgresql://192.168.1.7:5432/bdtest";
String user = "user";
String password = "123";
Class.forName(driver);
Connection conn = DriverManager.getConnection(connectString, user, password);
return conn;
}
}
When I compile the code it returns to me this error in this line:
JasperPrint jasperPrint=JasperFillManager.fillReport(fileName, parameters, getConnection());
the error message is:
Error loading object from file : C:\reports\rep_cli.jasper
I don't know what is the problem
can you help me?
I am desperate