Creating JDBC connection to Oracle Database using Java code
Below is the java code to create connection to database
External Jar required: ojdbc6-11.2.0.3.jar
public Connection getJDBConnection(){
String methodName = "getJDBConnection";
logger.setMethodStartLog(className, methodName);
String jdbcDriver = "oracle.jdbc.OracleDriver";
String dbUrl = "jdbc:oracle:thin:@HOSTNAME:1521:IDMDEV1";
String username = "USERNAME";
String password = "PASSWORD";
try {
Class.forName(jdbcDriver);
jdbcConnection = DriverManager.getConnection(dbUrl,username,password);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
logger.setMethodFinishLog(className, methodName);
return jdbcConnection;
}
You can use Platform.getOperationalDS().getConnection() method to establish oim connection using OIM API
Prepared Statements
Declaration:
PreparedStatement psActiveUsers = null;
Initialization:
psActiveUsers = conn.prepareStatement(queryInString);
Updating query parameters:
psActiveUsers.setString(1, lastRunTime);
Executing:
psActiveUsers.executeUpdate();
External Jar required: ojdbc6-11.2.0.3.jar
public Connection getJDBConnection(){
String methodName = "getJDBConnection";
logger.setMethodStartLog(className, methodName);
String jdbcDriver = "oracle.jdbc.OracleDriver";
String dbUrl = "jdbc:oracle:thin:@HOSTNAME:1521:IDMDEV1";
String username = "USERNAME";
String password = "PASSWORD";
try {
Class.forName(jdbcDriver);
jdbcConnection = DriverManager.getConnection(dbUrl,username,password);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
logger.setMethodFinishLog(className, methodName);
return jdbcConnection;
}
You can use Platform.getOperationalDS().getConnection() method to establish oim connection using OIM API
Prepared Statements
Declaration:
PreparedStatement psActiveUsers = null;
Initialization:
psActiveUsers = conn.prepareStatement(queryInString);
Updating query parameters:
psActiveUsers.setString(1, lastRunTime);
Executing:
psActiveUsers.executeUpdate();
Comments
Post a Comment