A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Databases
»
JDBC
Author
Proper place to initiate DB Pooling
Dilip kumar
Ranch Hand
Joined: Oct 16, 2000
Posts: 360
posted
Dec 28, 2005 12:48:00
0
Hi All,
I'm creating the DB connection pool in the init(). Is this the proper way ? Thanks
Main.java (
servlet
)
public void init() throws ServletException { utilClass = new Common(); super.init(); }
Common.java
public Common() { DB = new DBBean(); }
DBBean.java (implements Serializable)
private static DBBroker broker = null; protected Connection getConnection() throws Exception { if(broker == null) { broker = DBBroker.getHandle(); } return broker.getConnection(); }
DBBroker.java
private DBBroker() { init(); } private void init() { logger = Logger.getLogger(this.getClass().getName()); try { InitialContext ctx = new InitialContext(); ds = (DataSource) ctx.lookup("java:/testDS"); } catch(Exception e) { logger.error(e); } } public static synchronized DBBroker getHandle() { if(broker == null) { broker = new DBBroker(); } return broker; } public synchronized Connection getConnection() throws Exception { return ds.getConnection(); }
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: Proper place to initiate DB Pooling
Similar Threads
Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
LAST_INSERT_ID() with threads
Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
IBM Websphere 5 Connection Pool
Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter