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