Getting data from Database

By: Albert - jagerkiss
Getting data from Database
2002-09-05 01:38
Hi Teodor,

I've read your example code:

<%@ page errorPage="jasperError.jsp" %>
<%@ page import="dori.jasper.engine.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.awt.*" %>

<%
String driver = "weblogic.jdbc.mssqlserver4.Driver";
String connectString = "jdbc:weblogic:mssqlserver4:kermit:1433?db=Northwind";
String user = "sa";
String password = "";


Class.forName(driver);
Connection conn = DriverManager.getConnection(connectString, user, password);

JasperReport jasperReport = null;
jasperReport = JasperManager.loadReport("../data/FirstJasper.jasper");

//Preparing parameters
Image image = Toolkit.getDefaultToolkit().createImage("dukesign.jpg");
MediaTracker traker = new MediaTracker(new Panel());
traker.addImage(image, 0);
try
{
traker.waitForID(0);
}
catch (Exception e)
{
e.printStackTrace();
}

Map parameters = new HashMap();
parameters.put("ReportTitle", "The First Jasper Report Ever");
parameters.put("MaxOrderID", new Integer(10500));
parameters.put("SummaryImage", image);

JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, parameters, conn);

ByteArrayOutputStream baos = JasperManager.printReportToPdf(jasperPrint);

response.setContentType("application/pdf");
response.setContentLength(baos.size());
ServletOutputStream outStream = response.getOutputStream();
baos.writeTo(outStream);
outStream.flush();
%>

I still don't know which part of this code do the query to database. All I could find was code fragment which did making connection to database.

So my question is, where can I insert my query string?

Thanks,
Albert


By: Teodor Danciu - teodord
RE: Getting data from Database
2002-09-05 02:41

Hi,

The SQL query is specified in the XML report
template.
See the "queryString" element in the
"Quick Reference".

This XML report template was initially compiled
to obtain that .jasper file you see in the code.

Take a look at the docs. I know they are not much,
but at least you get an idea about the whole thing.

I hope this helps.
Teodor



By: Albert - jagerkiss
RE: Getting data from Database
2002-09-05 18:49
Hi again, Teodor!

While I was trying to compile an xml file with ant, I received error message "file:C:/ALBERT/TEST/FirstJasper.xml:17: Config file is not of expected XML type" (with file FirstJasper had been edited).

<jasperReport

name="FirstJasper"
columnCount="2"
printOrder="Vertical"
pageWidth="595"
pageHeight="842"
columnWidth="270"
columnSpacing="15"
leftMargin="20"
rightMargin="20"
topMargin="30"
bottomMargin="30"
isTitleNewPage="false"
isSummaryNewPage="false"> ---------> this is the 17th line.

What makes this error?

Thanks a lot,
Albert
2001 JI Open Discussion's picture
Joined: Aug 10 2006 - 3:26am
Last seen: 16 years 10 months ago

0 Answers:

No answers yet
Feedback
randomness