Java Utililty Methods JDBC Oracle Connection

List of utility methods to do JDBC Oracle Connection

Description

The list of methods to do JDBC Oracle Connection are organized into topic(s).

Method

ConnectiongetConnection(String connectString)
get Connection
return getConnection(connectString, null, null);
ConnectiongetConnection(String dbType, String dbIp, String dbPort, String dbName, String userName, String password)
get Connection
String driver = getDriverName(dbType);
String url = getURL(dbType, dbIp, dbPort, dbName);
Class.forName(driver).newInstance();
return DriverManager.getConnection(url, userName, password);
ConnectiongetConnection(String ip, String serviceName, String uid, String pwd)
get Connection
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@" + ip + ":1521:" + serviceName;
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, uid, pwd);
return conn;
ConnectiongetDatabaseConnection()
get Database Connection
Connection conn = null;
try {
    conn = DriverManager.getConnection(getDbUrl(), getUser(), getPass());
} catch (SQLException e) {
    System.out.println("DBHelper failed to create database connection");
    e.printStackTrace();
return conn;
...
StringgetDBVersion(String dbSourceName, String server, int port, String dbName, String userid, String pwd)
get DB Version
StringBuffer sb = new StringBuffer();
Connection mainConn = null;
String driverName = getDriverName(dbSourceName);
String sql = null;
if (dbSourceName.equals("oracle")) {
    sql = "SELECT * FROM V$VERSION";
} else if (dbSourceName.equals("db2")) {
    sql = "SELECT service_level||'(FP'||fixpack_num||')' FROM TABLE (sysproc.env_get_inst_info()) as x";
...
ConnectiongetJDBCConn(String hostname, String port, String sid, String username, String pwd)
create by David.ze 2015/07/11 Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
String thinLink = "jdbc:oracle:thin:@" + hostname + ":" + port + ":" + sid;
conn = DriverManager.getConnection(thinLink, username, pwd);
return conn;
ConnectiongetJDBCConnection()
get JDBC Connection
try {
    Connection conn = null;
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "dms", "dms");
    return conn;
} catch (Exception e) {
    e.printStackTrace();
    return null;
...
ConnectiongetOracle10GConnection(String connIP, String port, String dbName, String username, String password)
get Oracle G Connection
Connection conn = null;
try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection(
            "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)" + "(HOST=" + connIP
                    + ")(PORT=" + port + ")))" + "(CONNECT_DATA=(SID=" + dbName + ")))",
            username, password);
} catch (ClassNotFoundException e) {
...
ConnectiongetOracleConn()
get Oracle Conn
try {
    Class.forName(pros.getProperty("oracleDriver"));
    return DriverManager.getConnection(pros.getProperty("oracleURL"), pros.getProperty("oracleUser"),
            pros.getProperty("oraclePwd"));
} catch (Exception e) {
    e.printStackTrace();
    return null;
ConnectiongetOracleConnection()
get Oracle Connection
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:caspian";
String username = "mp";
String password = "mp2";
Class.forName(driver); 
Connection conn = DriverManager.getConnection(url, username, password);
return conn;