Wednesday, August 8, 2012

Jasper subreport duplicate values

When you printing a collection of data, you have to use a subreport to print data.

There are parameters, that you can use to customize your printing.

But, default parameters set subreport to print duplicate values. To avoid that change following parameters as mentioned below.

In subreport component,

Print When Detail Overflows true
Stretch Type Relative to Tallest Object

In the components inside the subreport,

Print Repeated Values true
Remove Line When Blank  false
Print In First Whole Band         false
Print When Detail Overflows false
Blank When Null    true
Stretch With Overflow true
Stretch Type Relative to Tallest Object

This changes works fine in both iReport 3.5 & 3.7 versions.

Monday, July 30, 2012

Jasper Report Groovy Error

In .jrxml file, it is created using "groovy" language. It occurs error while converting .jrxml file to .jasper file.

Following is shown a error message occurs while converting to .jasper file.

Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException        
at java.lang.Class.forName0(Native Method)       
at java.lang.Class.forName(Class.java:247)        
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:157)        
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:115)       
at net.sf.jasperreports.engine.JasperCompileManager.getCompiler(JasperCompileManager.java:511)        
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:215)       
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:148)        
at src.JasperCheck.main(JasperCheck.java:31)Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.control.CompilationFailedException        
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)       
at java.security.AccessController.doPrivileged(Native Method)        
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)        
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)        
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)        
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)        
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)        ... 8 moreJava Result: 1

Solution to above error is to change .jrxml language type from "groovy" to "java"

Friday, July 27, 2012

Informix Database LOCK Transaction for UPDATE

In some cases, we have to lock records for update. Below code segments can be used for locking table and update desired record in informix database server.

  • statement.executeUpdate("Begin Work");
  • statement.executeUpdate("set transaction isolation level serializable");

Above code must be used be before the SELECT statement execution which must be UPDATE.
  • String sql_1="select * from table where name='sujith' FOR UPDATE";

Execute the sql and proceed with the business logic. When you want to UPDATE the table do the following.
  • String sql_2=update table set name="delp" where name="sujith";

Execute the UPDATE statement, like above statement.

Then use below command for commiting transaction to database.
  • statement.executeUpdate("commit");

Tuesday, July 24, 2012

Print When Expression in Jasper Report


In some cases, we need to filter data values while printing in the report.

There is a special feature in iReport for this called as "Print When Expression".
In this expression, you have to insert Boolean function to the iReport.

For example :-

new Boolean($P!(var_name).toString.equals("5"))

Suppose the parameter variable is "var_name". If the value of the "$P!(var_name)" is equal to "5", it will print the value. Else, it will print null/blank value.

Jasper report Pass SQL to report as parameter

In jasper report, parameters can be categorized into a few data types. According to the data type, parameter  value is attached single quote.

For example, parameter data type is String, it is attached single quote (') between parameter value.
In some cases, we have to pass whole SQL to jasper report to generate report.

If we sent the SQL as a parameter it will return error, because of adding single quotes to parameter.
Solution is to have a ! sign before the parameter value as shown is below.

If the parameter value is "Query", it can be avoided adding single quote to parameter like below.

$P!{Query}

NOTE :- SQL can be a normal SQL statement

Friday, June 1, 2012

Oracle data format

When inserting data into Oracle Database it is needed to format data. Here, it is shown, how is TIMESTAMP is used in Oracle.

id_ref_no_seq.nextval call the sequence created before. It will increase ref_no value by one and insert back into database.

insert into TABLE_NAME(ref_no,start_time) values(id_ref_no_seq.nextval,TO_TIMESTAMP('2012-06-01 11:41:20.061', 'YYYY-MM-DD HH.MI.SSXFF'))

Wednesday, May 30, 2012

Create SEQUENCE in Oracle

In Oracle DB, there is no AUTO_INCREMENT field like MySQL. Oracle has SEQUENCE instead of this. Below command can be used to create SEQUENCE in Oracle.

CREATE SEQUENCE id_your_seq MINVALUE 1 START WITH 1 INCREMENT BY 1 NOCACHE;