Thursday, December 26, 2013

Execute procedure in informix

Following command can be used to execute procedure in informix database server.
In informix "dbaccess" shell, execute the following command. This will run the "this_is_it" procedure with three parameters "1", "2" and "3".

execute procedure this_is_it ('1','2','3');

create procedure this_is_it(this CHAR(3), that CHAR(4), other CHAR(3))
select * from inff_charge into temp this_is_it;
end procedure;

Monday, December 23, 2013

Force use IPv4 instead of IPv6 in JAVA

Sometimes, Netbeans IDE can't communicate via HTTP over IPv6. In that cases, you can let IDE to use IPv4 protocol instead of IPv6.

Following JVM option can be used to communicate over IPv4.

Tuesday, December 10, 2013

Send nohup.out to different file

Following command can use to redirect nohup.out to different files.

nohup java -jar -Xms32m -Xmx64m  Application.jar  > AppLog.out &

Above command will redirect "Application.jar" output to "AppLog.out" file.

Tuesday, November 26, 2013


"JSch" is a library that can be used for SFTP connection. You have to follow following steps to create SFTP connection. For this secure connection, you need to download "jsch-0.1.50.jar" and add to the project.

1) Create SSH key

GitHub Shell can be used to create a SSH key pair for secure connection.

Reference :-

In Git Shell, execute following commands to create key pair for particular server.

ssh-keygen -t rsa -C your_machine_ip

Above command will create "" and "id_rsa" keys for connection between your PC and server.

id_rsa :- Private key of FTP client machine :- Public key of SFTP server machine

Reference :-

2) Write code snip to create connection and store file

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;

public class SFTP {

    public static void main(String[] args) throws SftpException {

Session session = null;
        Channel channel = null;

        try {
            JSch ssh = new JSch();
            session = ssh.getSession("sujith", "", 22);

            String identityfile = "d:/.ssh/id_rsa";


            channel = session.openChannel("sftp");
            ChannelSftp sftp = (ChannelSftp) channel;

            sftp.put("d:/test.pdf", "/apps/home/sujith/");
        } catch (JSchException e) {
        } catch (SftpException e) {
        } finally {
            if (channel != null) {
            if (session != null) {

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.

Wednesday, July 31, 2013

Count number of files in a directory using Linux command

Following command can be used to get number of files in the directory. This "maxdepth" option lets you to define maximum depth (sub directory levels) to search files.

find ./targetdir/ -maxdepth 20 -type f -follow | wc -l

Thursday, July 4, 2013

Create RSA public & private keys in Linux

Using following command you can create public & private keys in Linux.

ssh-keygen -t rsa

This command can be executed in any SSH enabled Linux machine. RSA keys will be stored in .ssh directory created in your home directory.

Thursday, April 25, 2013

Validate email address in JS

Following java script function can be used to check email validation.

function checkEmail() {        

var email = document.getElementById('txtEmail');      

  var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;        
   if (!filter.test(email.value)) {      
   alert('Please provide a valid email address');      
   return false;   

Wednesday, April 17, 2013

Informix set connection timeout


Above JDBC connection URL can be used for connection timeout issues in Informix database.

INFORMIXCONRETRY : connection retry times
INFORMIXCONTIME : connection time

Connection timeout can be occurred due to database slowness and after maximum connection reach.
You have to change JDBC connection URL.

Thursday, April 4, 2013

Verify HOST servers entrusted certificates in JAVA

In sometimes, it has to be trusted the certificates in JAVA client when applications are developed. This may occur when hosting URL doesn't match with certificate URL.

Following JAVA code can be used to verify host as a trusted host.

   static {

   public boolean verify(String hostname,
      sslSession) {
       if (hostname.equals("")) {
          return true;
          return false;

Sunday, March 24, 2013

MySQL cluster JDBC URL

Following code can be used to create a JDBC Connection to MySQL cluster. Here, cluster contains two nodes as &


url = "jdbc:mysql:loadbalance://
                + “,”
                + "?"
                + “user=YourUserName&password=YourPassword”
                + "&loadBalanceConnectionGroup=first&loadBalanceEnableJMX=false&autoReconnect=true";


Monday, March 18, 2013

Check application running in Linux


PID1=`ps -eaf | grep app1.jar |grep -v  grep |wc -l`
if [ $PID1 -eq 0 ]
        cd /apps/app1/
        java -jar -Xms32m -Xmx64m app1.jar &
        echo "app1.jar ....................................... Started"
        sleep 1
        echo "app1.jar      ..................................... Already Running"

Above script can be used to check application status. If "app1.jar" is running, it will be printed "Already Running" else, it will start the "app1.jar".

Friday, March 8, 2013

Find 12 months previous date

Following SQL commands can be used to find the date before 12 months

In Informix,
select * from table where connected_date  < today - (12 UNITS MONTH)

select * from table where added_date>DATE_ADD(TODAY,INTERVAL -12 MONTH)

Thursday, February 21, 2013

Gson convertion between Object & String

Following JAVA function can be used to convert "Response" object to "String".
Gson library need to add to project.

Gson gson=new Gson();
Response response=new Response();
response.setMessage("Test JSON");
String rtnStr=gson.toJson(response);
return rtnStr;
This code snip convert "String" to "Response" object.
Gson gson=new Gson();
Response r=gson.fromJson(str, Response.class);

Tuesday, February 19, 2013

Unzip batch of files in Linux

Following command can be used to unzip batch of files in Linux.

gzip -d *.gz

Rename batch of files in Linux

Following awk script can be used to rename list of files.
Here, it will rename ".txt.pdf" files into ".txt" files.

for k in *.pdf; 
do mv $k `echo $k | sed 's/txt.pdf/txt/g'`; 

Copy files from one location to another in Linux

Following "scp" command can be used to copy files from one location to another.

scp * sujith@

Monday, February 4, 2013

SQL concat string in informix

Suppose database contains mobile_no field which has records like "0715355403".....

If you want to remove front "0" and add "94", you can use the following SQL command.

select  "94"||mobile_no[2,10] from sms_request

This is can used in SQL where clause, too.

Thursday, January 17, 2013

Store certificate in key store

When it is using trusted certificate in JAVA, it needs to be stored in JAVA key store.

JAVA default key store is %JAVA_HOME/jre/lib/security/cacerts

Using following command you can create a specific key store.

keytool -keystore keystore_name -storepass changeit -file \export\home\root.cer -import -alias alias_name -trustcacerts

Then use the following JAVA code to use the created key store.

System.setProperty("", "./keystore_name ");
System.setProperty("", "changeit");
System.setProperty("", "JKS");

Wednesday, January 16, 2013

Restart JAVA Process in crontab

Following is a shell script which can be used for restart JAVA application. If Application active count is zero(0), then this script can be used to restart the process. This shell script can be called by a crontab.

cat /dev/null > nohup.out
PRGCOU=`ps -eaf|grep JAVAApp.jar |grep -v grep |wc -l`

if [ $PRGCOU -eq 0 ]
nohup java -Xms32m -Xmx64m -jar JAVAApp.jar &
sleep 3