tomcat-users mailing list archives

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

Ramy,

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
appropriate).

> 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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAknTYOAACgkQ9CaO5/Lv0PDmgACgsplbJtueEOrON9WQ/IJ04Xcc
OcQAoImb6KgWR1Csb2DjG1v7GkY3LJbP
=qc6f
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message