Resolution to JNDI DataSource=null problem - Mailing list pgsql-jdbc
From | Nick Johnson |
---|---|
Subject | Resolution to JNDI DataSource=null problem |
Date | |
Msg-id | Pine.BSF.4.30.0204202143520.1596-100000@yitiya.pair.com Whole thread Raw |
List | pgsql-jdbc |
After fighting with this thing all day, I've finally achieved resolution to the problem. I had so many things going wrong, it's a wonder I ever solved the problem. Just to recap: the problem was that whenever I looked up a jdbc DataSource object, it was found, but it was always null, so null pointer exceptions, and blah blah blah. I implemented a short-term workaround that falls back to making a brute-force jdbc connection, but I was never happy with that. First, my postgresql.jar had a conspicuously different size than the binary posted on their homepage. It turns out that when I built mine, I hadn't yet installed the JDBC optional package, and it wasn't in my classpath (obviously since it wasn't there), so the build process built it without XA support. To compound matters, I'd never downloaded jta.jar, or at least didn't have it installed for whatever reason. This was easily corrected and I installed the new postgresql.jar. Still, things were not working, and I battled for a long time before I realized I was doing something really profoundly stupid (isn't that always what happens?) While Googling, I happened upon a discussion of JNDI on the jguru site that mentioned words about Contexts and Paths and JNDI. As it turns out, I had foolishly misconfigured my Context, or at least I had it configured differently than I thought. While I was mucking with things earlier, I moved the docbase (don't ask why) and didn't change the path from the null path. But like an idiot, I was accessing my test servlet as http://localhost/new_docbase/test instead of http://localhost/test. There is a huge difference. /test knew about resources in the proper context. /new_docbase/test did not. But the fun was not yet to quit. Now I started getting classCastExceptions; it was griping that a EnabledDataSource could not be cast to a DataSource, which is silly, since obviously it can. The problem turned out to be a bunch of junk .jar files in the webapp's lib directory, which I happily rm'ed. I'm not sure what they were doing there in the first place. Their presense was clearly causing some kind of conflict and no doubt confusing the hell out of the poor JRE. Then I started getting connections, and threw a small party to celebrate. They weren't pooling properly, and I found some notes on the net about that as well. Instead of getting a datasource from the contect: DataSource ds = (DataSource)envCtx.lookup("jdbc/datafoo"); Connection c = ds.getConnection(); To get a connection from a pool with Tyrex, one does this: ConnectionPoolDataSource pds = (ConnectionPoolDataSource)envCtx.lookup("jdbc/datafoo"); PooledConnection ds = pds.getPooledConnection(); Connection c = ds.getConnection(); Hopefully my experiences here will be of help to others by way of searching the list :) Nick -- "The aptly-named morons.org is an obscenity-laced screed..." -- Robert P. Lockwood, Catholic League director of research Nick Johnson, version 2.0 http://www.spatula.net/
pgsql-jdbc by date: