-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCommonDAO.java
More file actions
44 lines (36 loc) · 1.14 KB
/
CommonDAO.java
File metadata and controls
44 lines (36 loc) · 1.14 KB
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
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;
// This class contains the DB Connection Only
// and all the DAO is calling the CommonDAO to
//reterive the connection
// Singleton - it is a design pattern
// Create Single Object Only
public class CommonDAO {
// 1. Eager Singleton - Object is already there when class is loaded
// 2. Lazy Singleton - Object create on demand
//private static CommonDAO commonDAOObject= new CommonDAO();
private static CommonDAO commonDAOObject ;
// this is private constructor
private CommonDAO(){
}
public static CommonDAO getObject(){
synchronized(CommonDAO.class){
if(commonDAOObject==null){
commonDAOObject = new CommonDAO();
}
}
return commonDAOObject;
}
public Connection getConnection() throws ClassNotFoundException, SQLException{
// To Read Property File
ResourceBundle rb = ResourceBundle.getBundle("db");
Class.forName(rb.getString("drivername"));
Connection con= DriverManager.
getConnection(rb.getString("dburl")
,rb.getString("userid")
,rb.getString("password"));
return con;
}
}