Skip to Content
author's profile photo Former Member
Former Member

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

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Oct 13, 2006 at 11:51 AM

    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

    http://www.sam-solutions.net

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.