This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes jndi issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "jndi issue" Watch "jndi issue" New topic

jndi issue

william gates
Ranch Hand

Joined: Feb 21, 2007
Posts: 112
I'm having an issue connecting to a DB2 database on a Websphere 6.0 app server.

Here is my connection code :


public boolean connect()
dbCon = abc.DB.DB_ConnectionBean.getConnection();
catch(Exception e)
System.out.print("Failed to connect to DB " + e);

return true;


public static Connection getConnection()throws Exception
// Obtain our environment naming context
ctx = new InitialContext();
Context envCtx = (Context) ctx.lookup("java:comp/env");

// Look up our data source
DataSource ds = (DataSource)envCtx.lookup("jdbc/ABCDEFG");

// Allocate and use a connection from the pool
dbCon = ds.getConnection();

here is the web.xml piece :

<resource-ref id="somethingABC">
<description>abc stuff</description>

but when I deploy the webapp and try to run the jsp page, it comes back with this error on the jsp page :


Error 500: [IBM/DB2][T2zos/2.9.32]T2zosPreparedStatement.readPrepareDescribeOutput_:nativePrepareInto:1377 B2 engine SQL error, SQLCODE = -904, SQLSTATE = 57011, error tokens = 00D31024;00001004;NULL.CIM202.?RRSAF


I looked up the SQLCODE = -904 but it seems maybe I'm setting up the JNDI wrong. I'm not sure..

When I was testing on tomcat, we were using jdbc and we connected successfully and ran reports.

After migrating to webpshere 6.0, the server admins set up the jndi and according to their test page, our database connection pool works.. However I can't seem to access it. I've got the right names according to the server admin so I don't know.

I even tried using JSTL SQL tags to see if I could connect, but either I got an error or instead of results from the DB, i got the varialbles like $ColName as my results and not any real data.

I'm a little confused at this point. Any help on why my jndi isn't working would be appreciated.
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 9957

Originally posted by william gates:
[IBM/DB2][T2zos/2.9.32]T2zosPreparedStatement.readPrepareDescribeOutput_:nativePrepareInto:1377 B2 engine SQL error, SQLCODE = -904, SQLSTATE = 57011, error tokens = 00D31024;00001004;NULL.CIM202.?RRSAF

Going by this error message, it does not appear to be a jndi issue. Looks like you have successfully looked up the datasource but while getting the connection from that datasource the exception is being thrown (the error is from the DB server). You might have to check the connection properties that you have set for the datasource

[My Blog] [JavaRanch Journal]
william gates
Ranch Hand

Joined: Feb 21, 2007
Posts: 112
Thanks for your reply. I didn't set the datasource.. I only set up my connection bean, the web.xml and so on.

The server Admin handles the websphere 6.0 server and the connection pooling and so on. For security reasons I have no access to any of that information. I only know whatever the server admin reveals is the datasource name. And from there I thought the way I did things it should work. But it hasn't.

thanks for your reply though.
I agree. Here's the link:
subject: jndi issue
Similar Threads
Naming Exception happened when trying to connect to Oracle in Sun One Application Ser
JNDI lookup problem, this is a nightmare....
DSN name not found error with TOMCAT5.5.7
making connection pool in Glassfish v3
JMS and Websphere 6