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)