tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: DataSource from Context files - doesn't work
Date Wed, 01 Apr 2009 12:41:04 GMT
Hash: SHA1


Ugh... I wrote a longer reply and did something stupid with it
(fat-fingered the keyboard... something over by the ENTER/SHIFT/UP keys
and the message just disappeared). You're getting the short-short version.

On 3/31/2009 9:36 PM, Mighty Tornado wrote:
>     validationQuery="select * from family_member;"

This sucks. Use validationQuery="/* PING */SELECT 1" instead.

Your stack trace doesn't include what actually happened, which others
have pointed out. You say that it's not happening anymore and is
probably old. I suspect an NPE because...

> InitialContext ic = new InitialContext();
> if(ic == null)
> {
> System.out.println("context not found");
> }

You don't abort the operation at this point. ic.lookup() will still
execute, but ic is null, so you get an NPE. You should do something like
throw an exception or even return null (or an empty list or whatever is

> DataSource ds =
> (DataSource)ic.lookup("java:comp/env/jdbc/vhousehold");
> if(ds == null)
> {
> System.out.println("DataSource not found");
> }

Same here. If your DataSource is null, you still call getConnection() on
it. NPE.

> conn = ds.getConnection();
> stat = conn.createStatement();
> rs = stat.executeQuery("SELECT * FROM family_member ");

So, rs is null at this point? Are you sure it's rs and not something
like ic or ds? Try adding logging statements after each "real" line of
code and print out the values of these five local variables: ic, ds,
conn, stat, rs.

- -chris
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message