Jasper Report Export All Formats (Passing Parameters) using JSP Page

October 26, 2009
<%@ page language="java"  import="net.sf.jasperreports.engine.,net.sf.jasperreports.engine.export."  %>
<%@ page import="java.sql.,java.io.,java.util."  %>
<html>
<head>
<title>report generation in  jsp</title>
</head>
<body>
<%
String filename =  request.getParameter("filename");
String reporttype =  request.getParameter("reporttype");
String Paramtype =  request.getParameter("paramtype");;

/*creating database  connection/
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection  conn =  DriverManager.getConnection("dburl","user","pwd");
System.out.println("Connection  Established");

// jasperParameter is a Hashmap contains the  parameters
// passed from application to the jrxml layout
Map  jasperParameter = new  HashMap();
jasperParameter.put("paramtype",Paramtype);

/file path  of .jasper file/
String path =  application.getRealPath("/");
JasperPrint jasperPrint =  JasperFillManager.fillReport(path "/" filename, jasperParameter,  conn);
//JasperPrint jasperPrint = JasperFillManager.fillReport(path "/" filename, null, conn);
System.out.println("Report Created... in  "reporttype " Format");
OutputStream ouputStream =  response.getOutputStream();
JRExporter exporter = null;

/Report  generated in - PDF/
if( "pdf".equalsIgnoreCase(reporttype)  )
{
response.setContentType("application/pdf");
response.setHeader("Content-Disposition",  "inline; filename=\"report.pdf\"");

exporter = new  JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT,  jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,  ouputStream);
}

/Report generated in - rtf/
else if(  "rtf".equalsIgnoreCase(reporttype)  )
{
response.setContentType("application/rtf");
response.setHeader("Content-Disposition",  "inline; filename=\"report.rtf\"");

exporter = new  JRRtfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT,  jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,  ouputStream);
}

/Report generated in - html/

else if(  "html".equalsIgnoreCase(reporttype)  )
{
response.setContentType("application/html");
response.setHeader("Content-Disposition",  "inline; filename=\"report.html\"");

exporter = new  JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT,  jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,  ouputStream);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,"image?image=");
}
/Report  generated in - xls/

else if( "xls".equalsIgnoreCase(reporttype)  )
{
response.setContentType("application/xls");
response.setHeader("Content-Disposition",  "inline; filename=\"report.xls\"");
exporter = new  JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT,  jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,  ouputStream);
}

/Report generated in - csv/

else if(  "csv".equalsIgnoreCase(reporttype)  )
{
response.setContentType("application/csv");
response.setHeader("Content-Disposition",  "inline; filename=\"report.csv\"");

exporter = new  JRCsvExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT,  jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,  ouputStream);
}

try
{
exporter.exportReport();
}
catch  (JRException e)
{
throw new  ServletException(e);
}
finally
{
if (ouputStream !=  null)
{
try
{
ouputStream.close();
}
catch (IOException  ex){}
}
}
%>
</body>
</html>

Jasper Composer


Oracle Date – Time Arithmetic Calculations

September 7, 2009

Subtracting the two dates and find Years,Months and Days

Calculating Years , Months, and Days from the Current date with whole values as below shown oracle query updates.

select months_between(
to_date(‘03/06/2001′,’MM/DD/YYYY’),to_date(‘11/17/1992′,’MM/DD/YYYY’))/12 as “Years” from dual;

Years
———————-
8.30376344086021505376344086021505376344

select months_between(to_date(‘03/06/2001′,’MM/DD/YYYY’), to_date(‘11/17/1992′,’MM/DD/YYYY’)) as “Months” from dual;

Months
———————-
99.64516129032258064516129032258064516129

select to_date(‘03/06/2001′,’MM/DD/YYYY’) – to_date(‘11/17/1992′,’MM/DD/YYYY’) as “Total Days” from dual;

Total Days
———————-
3031

Calculating Years , Months, and Days from the Current date with calculated values from the query updates.

select trunc(months_between(to_date(‘07/09/2009′,’MM/DD/YYYY’), to_date(‘12/12/1975′,’MM/DD/YYYY’))/12) as “Years” from dual;

Years
———————-
33

select mod(trunc(months_between(to_date(‘07/09/2009′,’MM/DD/YYYY’),to_date(‘12/12/1975′,’MM/DD/YYYY’))),12) as “Months” from dual;

Months
———————-
6

select trunc(to_date(‘07/09/2009′,’MM/DD/YYYY’) – add_months(to_date(‘12/12/1975′,’MM/DD/YYYY’),
months_between(to_date(‘07/09/2009′,’MM/DD/YYYY’), to_date(‘12/12/1975′,’MM/DD/YYYY’)))) as “Days” from dual;

Days
———————-
27

and finally complete single query to fetch the Total Years , Months and Days

select trunc(months_between(to_date(‘07/09/2009′,’MM/DD/YYYY’), to_date(‘12/12/1975′,’MM/DD/YYYY’))/12) as “Years” ,
mod(trunc(months_between(to_date(‘07/09/2009′,’MM/DD/YYYY’),to_date(‘12/12/1975′,’MM/DD/YYYY’))),12) as “Months”,
trunc(to_date(‘07/09/2009′,’MM/DD/YYYY’) – add_months(to_date(‘12/12/1975′,’MM/DD/YYYY’),
months_between(to_date(‘07/09/2009′,’MM/DD/YYYY’), to_date(‘12/12/1975′,’MM/DD/YYYY’)))) as “Days” from dual;

Years Months Days
———————- ———————- ———————-
33 6 27

1 rows selected

The other way to work out the same problem in the below :

If you want a solution which breaks the days in years and month you can use the following query. We will use a leap year date, 01/01/2000 for example, for temporary purposes. This date will provide accurate calculation for most cases.

DEFINE DateDay = 8752.44056

SELECT

TO_NUMBER(SUBSTR(A,1,4)) – 2000 years,

TO_NUMBER(SUBSTR(A,6,2)) – 01 months,

TO_NUMBER(SUBSTR(A,9,2)) – 01 days,

SUBSTR(A,12,2) hours,

SUBSTR(A,15,2) minutes,

SUBSTR(A,18,2) seconds

FROM (SELECT TO_CHAR(TO_DATE(‘20000101′,’YYYYMMDD’)

+ &DateDay,’YYYY MM DD HH24:MI:SS’) A

FROM DUAL);

YEARS MONTHS DAYS HO MI SE

———- ———- ———- — – –

23 11 17 10 34 24

The new TIMESTAMP datatype

Convert DATE datatype to TIMESTAMP datatype

CREATE TABLE date_table (

date1 DATE,

time1 TIMESTAMP,

time2 TIMESTAMP

);

INSERT INTO date_table (date1, time1, time2)

VALUES (SYSDATE,

TO_TIMESTAMP (‘17.12.1980:00:00:00′,’DD.MM.YYYY:HH24:MI:SS’),

TO_TIMESTAMP (‘03.12.2004:10:34:24′,’DD.MM.YYYY:HH24:MI:SS’)

);

COMMIT;

SELECT CAST(date1 AS TIMESTAMP) “Date” FROM date_table;

Date

—————————————————————————

03-DEC-04 11.36.45.000000 AM

Formatting of the TIMESTAMP datatype:

SELECT TO_CHAR(time1,’MM/DD/YYYY HH24:MI:SS’) “Date”

FROM date_table;

Date

——————-

12/17/1980 00:00:00

Formatting of the TIMESTAMP datatype with fractional seconds:

SELECT TO_CHAR(time1,’MM/DD/YYYY HH24:MI:SS:FF3′) “Date”

FROM date_table;

Date

—————————–

12/17/1980 00:00:00:000


Silent Valley Trip @ Kovai

August 26, 2009

from – K810i @ Kovai

August 12, 2009

GKNM @ Kovai

August 12, 2009

TOMCAT – BlazeDS – JavaClass

March 17, 2009

BlazeDS – Tomcat – Java Class Configuration for Flex3 Version

STEP -I
Tomcat Configuration

 1. Installing Apache Tomcat Version in any of your Root Folder (ver. -6.0.18)
 2. In the Bin Folder the Tomcat Service can be start / stop
 3. User / Password for Tomcat Service may added in — “tomcat-users.xml”
 4. Port can change in “server.xml” file default Port is :8080 for BlazeDS 8400
 5. Every Configuration the Service should Stop and Start.

 

STEP – II
BlazeDS Configuration

 1. blazeds.war (downloaded)  file should place in \Tomcat[xxxx]\webapps folder
 2. After place the file the “blazeds” folder and insider created..(Automatically)
 3. in  “\webapps\blazeds\flex” some of xml file is available for configuration like remoting
    proxy-config, service-config,messaging-config files (depends upon developer request)

 

STEP – III
Java Class files
 1. In the \webapps\blazeds\WEB-INF\classes  – created classes can put inside…(relevant path)
STEP – IV
Configuration in Flex-3

 

11

 

2


BlazeDS, and Java Together – A Simple Tutorial

March 17, 2009

Steps for Using Flex With Java

1. Note my development system setup. If your system setup is different then you’ll need to adjust these instructions.

a. Windows XP

b. Tomat 6.0 installed in C:\Program Files\Apache Software Foundation\Tomcat 6.0\ referred to as [tomcat-home]

c. Tomat server running on port 8080

d. Flex Builder 3

2. These instructions assume you know how to do the following:

a. Create Java classes

b. Use Flex Builder 3

c. Stop and start Tomcat

3. Download BlazeDS (these instructions are as of June 22, 2008)

a. http://opensource.adobe.com/wiki/display/blazeds/Release+Builds

b. Download the BlazeDS binary distribution

 i. Save the .zip file to your computer

ii. There are two files in the zip – blazeds.war and blazeds-bin-readme.html

iii. Extract blazeds.war to your [tomcat-home]\webapps directory

c. Stop Tomcat if it’s running and then start Tomcat

d. In Windows Explorer navigate to the folder [tomcat-home]\webapps

 i. You should now have a folder named blaseds

ii. Under blazeds is a folder named web-inf

 iii. Under web-inf are several folders, one called classes is where we will put our Java classes so that our Flex application may use them.

iv. Under the folder flex is an xml file named remoting-config where we will put an XML node that tells our Flex application how to connect to the Java class

4. Using a Java IDE (for example Eclipse or Flex Builder 3 with the Java plug-in) create the following Java source file named HelloWorld.java.

package example;

public class HelloWorld {

public HelloWorld() {

}

public String getHelloWorld() {

return “Hello From Java!”;

}

}

Compile the Java source file into a class file (HelloWorld.class). Since our source file specified a package of example, our class file should be under a folder named example.

a. Copy the example folder to [tomcat-home]\webapps\blazeds\WEB-INF\classes

5.  Add the following node to [tomcat-home]\ webapps\blazeds\WEB-INF\flex\remoting-config.xml right after the closing </default-channels> node and before the closing </service> node. Note the values for id attribute and the value for the source tag (the complete path and name of our Java class).

<destination id=”helloworld”>

<properties>

<source>example.HelloWorld</source>

</properties>

<adapter ref=”java-object”/>

</destination>

6. Stop Tomcat if its running and start Tomcat

7. Create a new Flex Project named HelloWorld

a. In the New Flex Project wizard select J2EE as the Application Server type (see the very limited instructions here for some help)

b. Make sure Use remote object access service is checked

c. Click next

d. On the configure J2EE server uncheck use default location for local LiveCyle Data Services server

e. Specify the following values for root folder, root URL, and context root

 i. Root folder: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\blazeds

                                                       ii. Root URL: http://localhost:8080/blazeds

                                                      iii. Context root: /blazeds

f.  Click on the Validate Configuration button – should get the message “The web root folder and root URL are valid.”

g. Click Next and then click Finish

8. In your HelloWorld.mxml create the following source between the <mx:Application> </mx:Application> tags

<mx:Script>

<![CDATA[

import mx.rpc.events.ResultEvent;

import mx.rpc.events.FaultEvent;

import mx.utils.ObjectUtil;

import mx.controls.Alert;

import mx.utils.StringUtil;

private function resultHandler(event:ResultEvent):void

{

//used for debugging - shows details about result

//returned by the Java class method

Alert.show( ObjectUtil.toString(event.result) );

}

private function faultHandler(event:FaultEvent):void

{

Alert.show( ObjectUtil.toString(event.fault) );

}

]]>

</mx:Script>

<mx:RemoteObject id=”ro” destination=”helloworld

source=”example.HelloWorld

result=”resultHandler(event)”

fault=”faultHandler(event)”/>

<mx:Panel x=”10” y=”10” width=”440” height=”200” layout=”vertical” title=”Test Flex 3 Using Java” borderColor=”#008040” fontFamily=”Arial” fontWeight=”bold” fontSize=”13>

<mx:Text text=”Click The Button To Test Getting Data Into Flex From A Java Class” fontWeight=”bold” width=”250/>

<mx:Spacer height=”20/>

<mx:Button label=”Get Hello World!” click=”ro.getHelloWorld()”/>

</mx:Panel>

9. Run the Flex HelloWorld application. You should see an HTML file with a Flex panel and a Get Hello World! button. Click on the button and a Flex Alert component should appear with the words “Hello from Java!”.

10. Note in the mx:RemoteObject tag the value for destination matches the id attribute value and our source matches the value for the source tag in our destination node in the remote-config.xml file.

Trouble-shooting Tips

If you change the HelloWorld Java file then you’ll need to copy the new class file into the [tomcat-home]\webapps\blazeds\WEB-INF\classes folder in the correct package. Then you’ll have to stop and restart Tomcat.

If you change the remote-config.xml file, you’ll need to stop and restart Tomcat. You may also need to rebuild your Flex application before running it again.

Summary:

How easily Flex works with ColdFusion Components (CFCs) is just another reason I miss ColdFusion. But my new company uses Java to develop their web applications and they are not going to change to ColdFusion. But I hope that eventually we will be able to use Flex on the front end and Java on the back end where it makes sense. But first I’ve got to get smart on how to integrate Flex and Java. So I’ve got alot of learning and trial and error. I’ll keep you posted in this series of blog entries.

Up next – sending information from Flex to a Java class.

References

  1. LiveCycle Developer Center
  2. LiveCycle ES vs LiveCycle DS vs BlazeDS – clearing up the confusion
  3. BlazeDS and LCDS Feature difference
  4. BlazeDS Overview
  5. BlazeDS
  6. Creating Flex Builder Projects that Use Server Technologies

 

From Bruce Phillips Blog on Java, ColdFusion, Flex and Spry


Flex Videos & Training

March 11, 2009

Day 1: Flex basics

Day 2: Component development


Day 3: Putting it all together

Day 4: Adding visual appeal


Day 5: Architecture and advanced topics


SQL Server Releases

December 9, 2008
SQL Server Release History
Version Year Release Name Codename
1. 1989     SQL Server 1.0                                           -
4.21 1993 SQL Server 4.21 -
6.0 1995 SQL Server 6.0 SQL95
6.5 1996 SQL Server 6.5 Hydra
7.0 1998 SQL Server 7.0 Sphinx
- 1999 SQL Server 7.0 Tools Plato
8.0 2000 SQL Server 2000 Shiloh
8.0 2003 SQL Server 2000
64-bit Edition
Liberty
9.0 2005 SQL Server 2005 Yukon
10.0 2008 SQL Server 2008 Katmai

with M.Sc(IT) Friends

November 25, 2008