commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk Verbeeck <dirk.verbe...@pandora.be>
Subject Re: [DBCP] Usage Question
Date Sun, 14 Dec 2003 19:28:40 GMT
You declared "DataSource ds" inside the constructor and that "ds" is 
being initialized and not the "private DataSource ds".

-- Dirk


Vernon Smith wrote:
> After following the TC instruction configure the DBCP with the container, I create a
class to make a cleaner interface. 
> 
> public class DBCPWrapper {
> 	private DataSource ds;
> 
> 	public DBCPWrapper() {
> 		try {
> 			Context ctx = new InitialContext();
> 			if (ctx == null)
> 				throw new Exception("Boom - No Context");
> 			DataSource ds =
> 				(DataSource) ctx.lookup("java:comp/env/jdbc/postgres");
> 			} catch (Exception e) {
> 				e.printStackTrace();
> 		}
> 	}
> 
> 	public Connection getConnection() throws SQLException {
> 		Connection conn  = ds.getConnection(); <-- ds is NULL
> 		return conn;
> 	}
> }
> 
> I don't understand why the data source is null in the getConnection method. I fix this
problem by moving the body of the construtor into the getConnection method. I am not sure
that is a right approach thought. Is a better way to get the thing done?
> 
> Thanks for your inputs.



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message