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("javax.net.ssl.trustStore", "./keystore_name ");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("javax.net.ssl.trustStoreType", "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 ]
then
nohup java -Xms32m -Xmx64m -jar JAVAApp.jar &
sleep 3
exit
fi

Tuesday, December 4, 2012

Windows Username in JAVA

This is a simple code to retrieve windows username in JAVA.

public class getWindowUsername {
    public static final void main( String args[] ) {
      String userName = System.getProperty("user.name");
      System.out.println("Window's Username: "+userName);
   }
}

Monday, December 3, 2012

List files contains 'WORD' word

In Linux, grep command can be used to find files that contain specific word.

Change directory first to location where files are located.
Use following command to get file list

grep -l WORD *.*

Above command will list all files that contains word "WORD".

To get word location in file remove -l flag.

Thursday, November 29, 2012

AutoCommit enabled in MySQL DB

In MySQL default engine is set to "MyISAM". In  "MyISAM" engine, auto commit doesn't work. That means, you can't change commit time in application level. And, you can't roll back connections when needed when using "MyISAM" engine.

If you need to set auto commit enabled/ disabled in application level change MySQL DB engine to "INNODB" engine. In "INNODB" engine, you can roll back connection as needed.

CREATE TABLE Test1 (
  refNo varchar(10) default NULL,
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


CREATE TABLE Test1 (
  refNo varchar(10) default NULL,
) ENGINE=INNODB DEFAULT CHARSET=latin1;


Tuesday, November 27, 2012

Linux command hard disk space

Following command can be used to find hard disk space in Linux environment.

df -h

Wednesday, November 21, 2012

Copy data from one table to another table

You can copy data from one table to another table using following SQL command. This worked fine in informix database.

insert into TableA (field1, field2,field3)
select  field1, field2,field3 from TableB where added_on=today