I thought I had this problem fixed, but it has come up again.
Basically I'm just trying to grab a JDBC resource for a postgresql
database. My code looks something like this:
public static Connection getConnection(char mode)
throws NamingException, SQLException {
Context ctx = null;
ctx = new InitialContext();
Context envCtx = (Context) ctx.lookup("java:comp/env");
String dbname = "jdbc/" + (mode == 'w'? "dbrw" : "dbro");
DataSource ds = (DataSource) envCtx.lookup(dbname);
Connection c = ds.getConnection();
return c;
}
This code is called as a static method on a utility class from inside a
bean used by a JSP document.
Of course what happens is I get a null pointer exception trying to call
getConnection on ds. Here's the relevent information from server.xml.
I'll paste in only the entry for "dbrw". dbro is identical except it uses
a different username. Both have the same problem. I have verified that I
can log in both using the command line tool and a quick and dirty jdbc
test program.
<Resource name="jdbc/dbrw" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/dbrw">
<parameter>
<name>user</name>
<value>www</value>
</parameter>
<parameter>
<name>password</name>
<value>xxxxxxxx</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.postgresql.Driver</value>
</parameter>
<parameter>
<name>driverName</name>
<value>jdbc:postgresql://localhost:5432/main/value>
</parameter>
</ResourceParams>
And in web.xml (I've decided to use the server's web.xml rather than the
context's):
<resource-ref>
<description>
Resource reference to a java.sql.Connection factory
</description>
<res-ref-name>jdbc/dbrw</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
postgresql.jar and the jdbc extensions are in common/lib. As far as I can
tell from snooping traffic across lo0, no connection attempt is ever made,
although I do see plenty of traffic from my little jdbc test program.
Any pointers would be greatly appreciated, especially any information on
debugging problems with JNDI, getting diagnostic information out of it,
etc. A working postgresql config would be even better. My instinct about
this is that I have JNDI set up incorrectly, or the jdbc drivers are not
getting found or initialized properly, but having exhausted all my ideas,
I thought I'd ask for a pointer :)
Many thanks,
Nick
--
To unsubscribe: <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>