Sunday, October 27, 2013

Grouping data by SQL expression

Following SQL syntax can be used to group data using expression.

select date(added_time) as a,count(*) from test_table group by a                
This will group data by date and display its count. It doesn't work grouping with expression, So need to use alias naming for expression.

Wednesday, September 18, 2013

JAVA Resultset metadata information

In JAVA, you can use retrieve information about resultset using following code.

String str ="select * from table001";

ResultSet rs = st.executeQuery(str);
ResultSetMetaData rsmd = rs.getMetaData();

System.out.println("Number of columns - " + rsmd.getColumnCount());
System.out.println("JAVA data type for Table field 3 - "+rsmd.getColumnClassName(3));
System.out.println("Database Table field 3 type - "+rsmd.getColumnTypeName(3)); 

Tuesday, August 13, 2013

Avoid submitting form when enter key is pressed

Sometimes, you have to avoid submitting page when enter key is pressed. You need to add following style to  text box.

<input id="txtName" name="txtName" style="display: none;" type="text" />

Wednesday, August 7, 2013

Struts forward parameters to URL in action class

In some cases, you have to send additional parameters with the action forwarding.
Following code snip can be used to set additional parameters in the action class of the struts. 

ActionRedirect redirect = new ActionRedirect(mapping.findForward(forwardPage)); 
redirect.addParameter("username", "user"); 

redirect.addParameter("password", "PWD");
return redirect;

Tuesday, August 6, 2013

Find files which contains word using Linux command

Following Linux command can be used to find files which contains specific words. For example, if you need to search files which contain word "test", you can use the following command.

find . -exec grep -l "test" {} \;

Thursday, August 1, 2013

Avoid "Grid Layout Exception" in Jasper reports

When it is creating multiple reports by threads in Jasper, you will get "Grid Layout Exception" occurred by the jasper library. To avoid that, you can add the following property to JVM.

JRProperties.setProperty("net.sf.jasperreports.text.measurer.factory", "net.sf.jasperreports.engine.util.JdkGlyphFixTextMeasurerFactory");

How to get Linux bash command list

Type history in the Linux terminal and enter.

This will list all the commands you executed in the bash.