How many way we can get database connection and which one is best approaches and why ??
Basiacally there r two way to get:- connection from DB .
👉1.DriverManager
👉2.DataSource
but in real time 2nd one is preferable.coz in case of DriverManager we have to remember all the connection property to get connection from Db.nd it is also not reusablity nature. Suppose u create one connection obj then u can perform one time operation any other class can't reuse that connection again. .
so to over come it we use DataSource(I) to get connection .from DataBase.in nd case by using this DataResource
we achive connection pool concept.in this case we need not to set connection properties and we no need to take headach for creating object to get connection
that work is done/set by ADMIN in DataSource Implementation class object nd these property r bind with
JNDI(java naming directory interface) registry. we just lookup from registry to get that object nd make connection with DB.... ..
🌍.This whole concept is designed based on ServiceLocator Design Pattern
so it is most prefereble....
👉1.DriverManager
👉2.DataSource
but in real time 2nd one is preferable.coz in case of DriverManager we have to remember all the connection property to get connection from Db.nd it is also not reusablity nature. Suppose u create one connection obj then u can perform one time operation any other class can't reuse that connection again. .
so to over come it we use DataSource(I) to get connection .from DataBase.in nd case by using this DataResource
we achive connection pool concept.in this case we need not to set connection properties and we no need to take headach for creating object to get connection
that work is done/set by ADMIN in DataSource Implementation class object nd these property r bind with
JNDI(java naming directory interface) registry. we just lookup from registry to get that object nd make connection with DB.... ..
🌍.This whole concept is designed based on ServiceLocator Design Pattern
so it is most prefereble....
Comments
Post a Comment