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(        
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(        
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(       
at net.sf.jasperreports.engine.JasperCompileManager.getCompiler(        
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(       
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(        
at src.JasperCheck.main( by: java.lang.ClassNotFoundException: org.codehaus.groovy.control.CompilationFailedException        
at Method)        
at java.lang.ClassLoader.loadClass(        
at sun.misc.Launcher$AppClassLoader.loadClass(        
at java.lang.ClassLoader.loadClass(        
at java.lang.ClassLoader.loadClassInternal(        ... 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.


NOTE :- SQL can be a normal SQL statement