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 192.168.2.23 & 192.168.2.24.

Class.forName("com.mysql.jdbc.Driver").newInstance();

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

DriverManager.getConnection(url);

Monday, March 18, 2013

Check application running in Linux


#!/bin/bash

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

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)

In MySQL,
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.setStatus("OK");
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'`; 
done

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@192.168.1.153:/apps/sujith/data