commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jean-Pierre Pelletier" <>
Subject [commons-dbcp] BasicDataSource.getConnection(username, password) fails where setUsername(u), setPassword() succeed
Date Fri, 06 May 2005 13:48:21 GMT
Hi,  I am new to this list but I'll try to describe this clearly.

I had an tomcat application running fine with a single user name & password specified
in server.xml.

It now needs the user name and password to be specified at run time, so I
removed the user name and password from server.xml and change my connection code
to use DataSource.getConnection(username, password) instead of DataSource.getConnection().

final InitialContext ctx = new InitialContext();

final DataSource   ds  = (DataSource) ctx.lookup("java:comp/env/jdbc/claimDatasource");
final Connection connection = ds.getConnection("postgres","mypassword");

this throwed PSQLException Connection rejected: FATAL: no postgreSQL user name specified
Then I tried coding to class BasicDataSource using other methods not part of the
DataSource interface:

final InitialContext ctx = new InitialContext();
final BasicDataSource ds = (BasicDataSource) ctx.lookup("java:comp/env/jdbc/claimDatasource");
final Connection connection = ds.getConnection();

This worked fine, but I prefer to use a standard interface method DataSource.getConnection(u,p)
rather than non standard class methods BasicDataSource.setUsername(u) and .setPassword(p).

Is this a bug or am I doing something wrong?

My environment is:
- Windows XP Home Edition with Service Pack 2
- PostgreSQL 8.0.1
- JDBC PostgreSQL 8.0 JDBC 3 Build 311
- commons-dbcp 1.2.1 (bundled with Tomcat 5.0.27)
- sun java 1.4.2_05

Jean-Pierre Pelletier

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message