Monday, August 18, 2014

To check DB connectivity and DB response time

Hello All,

As a WebLogic Admins, we normally see lot of issue around jdbc like slowness connectivity etc,

So I am providing a simple program which will help us to check the connectivity as well as the DB response time via WebLogic dirver.

Try setting thr "setDomainEnv.sh" file before executing the program as you need ojdbc6(or 5).jar in the classpath.


import java.sql.*;
import java.util.*;

public class DConnect
{
public static void main(String args[])
{
try
{
String url =  new String(args[0]);
java.util.Properties props = new Properties();
Class.forName("oracle.jdbc.OracleDriver");
Driver d = new oracle.jdbc.OracleDriver();
props.put("user","username");
props.put("password","password");
while(true)
{
Connection con = d.connect(url,props);
System.out.println("Acquired connection using Driver.connect");
System.out.println(con);
System.out.println(System.currentTimeMillis());
con.close();
System.out.println("Connection Closed");
System.out.println(System.currentTimeMillis());
}
}

catch(Throwable e)
{
e.printStackTrace();
}
}

}


This is a infinite loop code which will connect to DB and print the timestamp and then close the connection.

In the above program, you can copy the url  from Admin Console -> DataSource -> Connection Pool ->URL