//Java Program for Oracle DB Connection
//Establish Connection
public static Connection getConnection(String dbURL,String dbUser,String dbPassword)
{
Connection oracleConnection = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String connURL = "dbURL";
String connUName = "dbUser";
String connPwd = "dbPassword";
oracleConnection = DriverManager.getConnection(connURL, connUName, connPwd);
if(oracleConnection!=null)
{
log.info("Oracle Connection made successfully.");
}
else
{
log.info("Oracle Connection not made successfully.");
}
} // End TRY
catch(Exception e)
{
log.error("Exception ---> " +e.getMessage());
e.printStackTrace();
} // End CATCH
log.debug("EXIT");
/* Return Statement */
return oracleConnection;
} // End METHOD: getConnection()
public static Connection getConnection(String dataSourceName){
log.info("Enter [OracleConnect]getConnection()");
log.info("Data Source Name is: "+dataSourceName);
Connection dbConnection=null;
try{
InitialContext ctx = new InitialContext();
Object objRef = ctx.lookup(dataSourceName);
DataSource dataSource = (DataSource)objRef;
dbConnection = dataSource.getConnection();
}catch(SQLException ex){
log.error("Exceptio found at [OracleConnect]getConnection():"+ex);
}catch(NamingException ex){
log.error("Exceptio found at [OracleConnect]getConnection():"+ex);
}catch(Exception ex){
log.error("Exceptio found at [OracleConnect]getConnection():"+ex);
}
return dbConnection;
}
// Close Connection
public static void closeConnection(Connection dbConnection) throws SQLException
{
try
{
if(dbConnection != null)
{
dbConnection.close();
log.info("Oracle Connection closed.");
} // End IF
} // End TRY
//Establish Connection
public static Connection getConnection(String dbURL,String dbUser,String dbPassword)
{
Connection oracleConnection = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String connURL = "dbURL";
String connUName = "dbUser";
String connPwd = "dbPassword";
oracleConnection = DriverManager.getConnection(connURL, connUName, connPwd);
if(oracleConnection!=null)
{
log.info("Oracle Connection made successfully.");
}
else
{
log.info("Oracle Connection not made successfully.");
}
} // End TRY
catch(Exception e)
{
log.error("Exception ---> " +e.getMessage());
e.printStackTrace();
} // End CATCH
log.debug("EXIT");
/* Return Statement */
return oracleConnection;
} // End METHOD: getConnection()
public static Connection getConnection(String dataSourceName){
log.info("Enter [OracleConnect]getConnection()");
log.info("Data Source Name is: "+dataSourceName);
Connection dbConnection=null;
try{
InitialContext ctx = new InitialContext();
Object objRef = ctx.lookup(dataSourceName);
DataSource dataSource = (DataSource)objRef;
dbConnection = dataSource.getConnection();
}catch(SQLException ex){
log.error("Exceptio found at [OracleConnect]getConnection():"+ex);
}catch(NamingException ex){
log.error("Exceptio found at [OracleConnect]getConnection():"+ex);
}catch(Exception ex){
log.error("Exceptio found at [OracleConnect]getConnection():"+ex);
}
return dbConnection;
}
// Close Connection
public static void closeConnection(Connection dbConnection) throws SQLException
{
try
{
if(dbConnection != null)
{
dbConnection.close();
log.info("Oracle Connection closed.");
} // End IF
} // End TRY
No comments:
Post a Comment