OIM DB Connection/ Data Source connection

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.massiveGaze.connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.massiveGaze.properties.OIMProfileReader;

/**
 *
 * 
 */
public class DataSource {
 private static Connection connectionObject = null;
 private static OIMProfileReader properties=null;
 static String JDBC_DRIVER = null;
 static String DB_URL = null;

 static String USER = null;
 static String PASS = null;

 private static Connection makeConnection() {

  try {   
   properties = new OIMProfileReader();
   JDBC_DRIVER=properties.getString("operationsDB.directDBdriver");
   DB_URL=properties.getString("operationsDB.jdbcUrl");
   USER=properties.getString("operationsDB.user");
   PASS=properties.getString("operationsDB.password");
   
   Class.forName(JDBC_DRIVER);
   System.out.println("Connecting to database...");
                        System.out.println("DB User Name -> "+DB_URL);
                        System.out.println("DB URL  -> "+USER);
                        
   connectionObject = DriverManager.getConnection(DB_URL, USER, PASS);
  } catch (SQLException se) {
     se.printStackTrace();
  } catch (Exception e) {
   
   e.printStackTrace();
  }
  return connectionObject;
 }

 public static synchronized Connection getConnection() {
  if (connectionObject == null) {
   connectionObject = makeConnection();
  }
  return connectionObject;

 }

 public static void closeConnection() {
             System.out.println("Closing  to database connection ...");
  try {
   properties=null;
   JDBC_DRIVER=null;
   DB_URL=null;
   USER=null;
   PASS=null;
   if (connectionObject != null)
    connectionObject.close();
  } catch (SQLException se) {
   se.printStackTrace();
  }
 }
 public static void main(String args[]){
  getConnection();
                closeConnection();
 }
}

No comments:

Post a Comment

About OIM

Oracle Identity Management enables organizations to effectively manage the end - to - end life - cycle of user ide...

Popular Posts