//Establish DB2 Connection
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.log4j.Logger;
/*
*@Rakesh K
*/
public class DB2Connect
{
public static Logger log=Logger.getLogger(DB2Connect.class);
public static Connection getConnection(String dbURL,String dbUser,String dbPassword)
{
log.debug("ENTER [DB2Connect]getConnection()");
/* Connection Variable */
Connection db2Connection = null;
try
{
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
/* Connection Parameters */
String connURL = "dbURL";
String connUName = "dbUser";
String connPwd = "dbPassword";
log.info("DB2 connection url:"+connURL+", for the User: "+connUName);
/*
* String connURL="jdbc:db2://localhost:50000/SAMPLEDB";
* DB2 Connection URL Pattern
*/
db2Connection = DriverManager.getConnection(connURL, connUName, connPwd);
if(db2Connection!=null)
{
log.info("DB2 Connection made successfully.");
}
} // End TRY
catch(Exception e)
{
log.error("Exception ----> " +e.getMessage());
log.error("Exception ----> " +e);
e.printStackTrace();
} // End CATCH
log.debug("EXIT");
/* Return Statement */
return db2Connection;
} // End METHOD: getConnection()
public static void closeConnection(Connection dbConnection) throws SQLException
{
try
{
if(dbConnection != null)
{
dbConnection.close();
log.info("DB2 Connection closed.");
} // End IF
} // End TRY
catch(SQLException e)
{
log.error("Exception ---> " +e.getMessage());
} // End CATCH
} // End METHOD: closeConnection()
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.log4j.Logger;
/*
*@Rakesh K
*/
public class DB2Connect
{
public static Logger log=Logger.getLogger(DB2Connect.class);
public static Connection getConnection(String dbURL,String dbUser,String dbPassword)
{
log.debug("ENTER [DB2Connect]getConnection()");
/* Connection Variable */
Connection db2Connection = null;
try
{
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
/* Connection Parameters */
String connURL = "dbURL";
String connUName = "dbUser";
String connPwd = "dbPassword";
log.info("DB2 connection url:"+connURL+", for the User: "+connUName);
/*
* String connURL="jdbc:db2://localhost:50000/SAMPLEDB";
* DB2 Connection URL Pattern
*/
db2Connection = DriverManager.getConnection(connURL, connUName, connPwd);
if(db2Connection!=null)
{
log.info("DB2 Connection made successfully.");
}
} // End TRY
catch(Exception e)
{
log.error("Exception ----> " +e.getMessage());
log.error("Exception ----> " +e);
e.printStackTrace();
} // End CATCH
log.debug("EXIT");
/* Return Statement */
return db2Connection;
} // End METHOD: getConnection()
public static void closeConnection(Connection dbConnection) throws SQLException
{
try
{
if(dbConnection != null)
{
dbConnection.close();
log.info("DB2 Connection closed.");
} // End IF
} // End TRY
catch(SQLException e)
{
log.error("Exception ---> " +e.getMessage());
} // End CATCH
} // End METHOD: closeConnection()
}
No comments:
Post a Comment