logo       

Resolution to JNDI DataSource=null problem: msg#00115

Subject: Resolution to JNDI DataSource=null problem
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/




---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
science.linguis...    culture.sf.lite...    video.mplayer.c...    yellowdog.gener...    ietf.rfc822/199...    emacs.help/2002...    redhat.release....    kernel.speakup/...    java.openejb.de...    debian.devel.gt...    xfree86.newbie/...    bug-tracking.ma...    pam/2003-05/msg...    games.devel.ope...    user-groups.lin...    music.pancham/2...    network.mq.deve...    web.html.genera...    arklinux.bugs/2...    linux.ecasound/...    qnx.openqnx.dev...    org.user-groups...    file-systems.sf...    trustix.contrib...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe