Skip to Content
0
Former Member
Oct 13, 2006 at 08:47 AM

sos:(WD + java )Report,not supporte JasperReport?

91 Views

<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();
	}
}