on 10-13-2006 9:47 AM
<b>following code can be executed successful in command line(start menu->run->cmd->javaC x.class->java x).but after i deploy it to server(07S7 portal),i cann't get the correct result.</b>
package com.test.report;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;
import java.util.Map;
import org.jdom.input.SAXBuilder;
import net.sf.jasperreports.engine.JasperManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.view.JasperViewer;
public class ReportX {
public void popView() {
try {
String xmlFile=this.getClassPath()+"/AlterDesignReport.jrxml";
// read xml file by jdom
SAXBuilder builder = new SAXBuilder();
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
InputStream input=contextClassLoader.getResourceAsStream(xmlFile);
JasperDesign jasperDesign = JasperManager.loadXmlDesign(input);
//****************************************************************
// debug here cann't going on.firstly it looks its running.
//after a while,report error:
// [toString() unavailable - no suspended threads]
//*****************************************************************
JasperReport jasperReport = JasperManager.compileReport(jasperDesign);
// Second, create a map of parameters to pass to the report.
Map parameters = new HashMap();
parameters.put("employeeChart", "createEmployeeChartImage");
// Third, get a database connection
Connection conn = this.getConnection();
// Fourth, create JasperPrint using fillReport() method
JasperPrint jasperPrint =
JasperManager.fillReport(jasperReport, parameters, conn);
// Or to view report in the JasperViewer
JasperViewer.viewReport(jasperPrint);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
Connection conn2 = null;
String connStr = "jdbc:sybase:Tds:192.168.0.1:10001/myDB";
String username = "xx";
String password = "xx";
try {
Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
try {
conn2 = DriverManager.getConnection(connStr, username, password);
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
return conn2;
}
public String getClassPath()
{
String strClassName = getClass().getName();
String strPackageName = "";
if(getClass().getPackage() != null)
{
strPackageName = getClass().getPackage().getName();
}
String str=strPackageName.replaceAll("\.","/");
return str;
}
public static void main(String[] args) {
ReportX rx=new ReportX();
rx.popView();
}
}
Wingoal,
You need at least 2 <b>external libraries</b> deployed on SAP WebAS to make this code run -- Jasper and Sybase JDBC driver.
The Sybase is simpler case: you have to define own DataSource and driver using Visual Administrator and re-write your code to use data source rather then explicit connection.
To learn how to create Jasper external library search this forum for term <b>external AND library</b>. I would also suggest my own blog post about external libraries, but it is a bit outdated.
Valery Silaev
SaM Solutions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.