Pages

Wednesday, October 19, 2011

Read Java servlet in ireport + convert seconds value to hh-mm-ss format

1.Create a java file        

        $ vim utils.java

package ronin.java.servlets;
public class sec_convert
{
        public static String hourFormat(String[] args)
        {
                int duration = Integer.parseInt(args[0]);
                int seconds = duration % 60;
                int minutes = ( duration % 3600 ) / 60 ;
                int hours = duration / 3600 ;


                StringBuffer buffer = new StringBuffer( 10 );


                buffer.append( hours < 10 ? "0" + hours : hours );
                buffer.append( ":" );
                buffer.append( minutes < 10 ? "0" + minutes : minutes );
                buffer.append( ":" );
                buffer.append( seconds < 10 ? "0" + seconds : seconds );


                return( buffer.toString() );
//              System.out.println(buffer.toString() );
        } 
}

Navigate to folder where source file is

2. Compile the class using following command
               $  javac -d . utils.java
this creates "ronin/java/servlets" folder structure

3.To make the jar file
               $ JAR CF jar_file_name.jar class_name.class
               $ jar cf utils.jar utils.class

4. Use following command in Ireport variable expression area

(new ronin.java.servlets.utils()).hourFormat($F{tot_duration_sec}.toString())


return values of $F{tot_duration_sec} field will be displayed in hh-mm-ss format

No comments:

Post a Comment