Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 13th, 2006, 04:15 PM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML to PDF using Jasper Report in JAVA

Hello,
I am doing a project to generate report from XML file to PDF file using Jasper in JAVA. But I am not familiar with Jasper as well as XML.
I need some help....

THanks

Reply With Quote
  #2 (permalink)  
Old February 9th, 2006, 02:24 AM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi ,
What ur problem?where did u stuck?

Did u worked any sample example

Reply With Quote
  #3 (permalink)  
Old February 21st, 2006, 03:24 AM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi ,

  Here i am sending some sample report generated in PDF format using jasper

1)save this file as stcokroom.jrxml in u r c drive.
2) change the database settings and query ...u will get

-------------
-----------------------------------

This Is My File (stockroom.jrxml)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="DataSourceReport" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="40" rightMargin="40" topMargin="50" bottomMargin="50">
<style name="Arial_Normal" isDefault="true" fontName="Arial" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<style name="Arial_Bold" isDefault="false" fontName="Arial" fontSize="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<style name="Arial_Italic" isDefault="false" fontName="Arial" fontSize="12" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Oblique" pdfEncoding="Cp1252" isPdfEmbedded="false"/>

<field name="STOCKROOM_ID" class="java.lang.Integer">
</field>
<field name="STOCKROOM_NAME" class="java.lang.String">
</field>
<field name="STOCKROOM_DESC" class="java.lang.String">
</field>

<pageHeader>
<band height="20">

<staticText>
<reportElement mode="Opaque" x="0" y="5" width="55" height="15" forecolor="#ffffff" backcolor="#333333" style="Arial_Bold"/>
<textElement textAlignment="Center"/>
<text><![CDATA[STOCKROOM_ID]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="55" y="5" width="205" height="15" forecolor="#ffffff" backcolor="#333333" style="Arial_Bold"/>
<text><![CDATA[STOCKROOM_NAME]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="260" y="5" width="255" height="15" forecolor="#ffffff" backcolor="#333333" style="Arial_Bold"/>
<text><![CDATA[STOCKROOM_DESC]]></text>
</staticText>

</band>

</pageHeader>
<detail>
<band height="15">
<textField bookmarkLevel="2">
<reportElement x="0" y="0" width="50" height="15"/>
<box leftBorder="Thin" bottomBorder="Thin" leftPadding="10" rightPadding="10"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$F{STOCKROOM_ID}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="50" y="0" width="200" height="15"/>
<box leftBorder="Thin" bottomBorder="Thin" leftPadding="10" rightPadding="10"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{STOCKROOM_NAME}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="250" y="0" width="265" height="15"/>
<box leftBorder="Thin" bottomBorder="Thin" rightBorder="Thin" leftPadding="10" rightPadding="10"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{STOCKROOM_DESC}]]></textFieldExpression>
</textField>




</band>
</detail>
</jasperReport>




----------------------


And This My Java Jasper Program for PDF:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;

import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;

public class JasperReportDemo
{
public static void main(String[] args) throws SQLException, FileNotFoundException,
IllegalAccessException, ClassNotFoundException,Exception
{

try
{

final String driverClass = "xxxxxxxxxxxxxxxxxx";
final String connectionURL = "xxxxxxxxxxxx ";
final String userID = "xxxxxxxxxxx";
final String userPassword = "zzzzzzzzzzzz";
Connection con = null;
Statement stmt = null;
ResultSet rset = null;
Class.forName(driverClass).newInstance();
con = DriverManager.getConnection(connectionURL, userID, userPassword);
String queryString = "SELECT STOCKROOM_ID, STOCKROOM_NAME, STOCKROOM_DESC "
+ "FROM stockroom ";
stmt = con.createStatement();
rset = stmt.executeQuery(queryString);
InputStream input = new FileInputStream(new File("c:/stockroom.xml"));
JasperDesign design = JRXmlLoader.load(input);
JasperReport report = JasperCompileManager.compileReport(design);
JRResultSetDataSource jasperReports = new JRResultSetDataSource(rset);
JasperPrint print = JasperFillManager.fillReport(report, new HashMap(), jasperReports);
long start = System.currentTimeMillis();

OutputStream output = new FileOutputStream(new File("c:/output/JasperReport.pdf"));
JasperExportManager.exportReportToPdfStream(print, output);



Reply With Quote
  #4 (permalink)  
Old October 12th, 2006, 05:41 AM
Registered User
 
Join Date: Oct 2006
Location: Pune, Maharastra, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to shashideore
Default

Hi raj_plkd,
I'm using the code you have provided here to export to pdf .It is working fine.
But i get an error "WARNING: The supplied java.sql.Connection object is null"
if i use a subreport in my main report.

Can you please help me resolve this problem.

Thanks in advance.


Shashikant Deore
Reply With Quote
  #5 (permalink)  
Old November 23rd, 2006, 12:42 AM
Registered User
 
Join Date: Aug 2006
Location: Mangalore, , India.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

why are u struggling lot , use i report for report generation and in action u can compile jasper report to pdf easily by 2 line code... try it

Reply With Quote
  #6 (permalink)  
Old November 24th, 2006, 07:59 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

connection object null means check man whether connection object is null or not

Regards
Kotaiah

Reply With Quote
  #7 (permalink)  
Old July 5th, 2007, 04:44 AM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

[Hi ,
this is sathiya. i have to generate jasperreport for app and i have xml form of input data, i need to convert xml into pdf format.

 i don't know how to compile the jasper program. is there any .jar file to compile that.

i need help. if any one aware of jasper process. please let me know for this mail id: j.sathiyamoorthy@gmail.com

thanks and regards,
sathiya

Reply With Quote
  #8 (permalink)  
Old December 7th, 2011, 01:43 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Location: bangalore
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Smile vijji

i dont have knowledge regarding jasper reports can u send me some tutorials regarding to jasper reports.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
jasper to pdf maktwin J2EE 1 March 11th, 2009 02:33 PM
jasper report with netbeans 5.0 gita_Sathyam Java Basics 0 April 14th, 2008 04:34 AM
Problems While generating pdf using Jasper kiran_p2p J2EE 0 December 27th, 2006 12:04 AM
how to run jasper report from java file? hiraal_thoria J2EE 1 March 14th, 2005 04:41 AM
jasper report devi.g@india.com J2EE 0 February 3rd, 2005 06:48 AM



All times are GMT -4. The time now is 11:27 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.