• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem using Datasource

Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm working in a project based on struts where we use Websphere 5.1 Application Server, with DB2 v9.0 as database server. We are trying to use Datasource via JNDI, but we can't get it working properly.

I've defined a new DB2 JDBC Provider in the server configuration file, and a DataSource that uses it with the following parameters:

Name: TestDataSource
JNDI name: jdbc/TestDataSource
Datasource helper classname: com.ibm.websphere.rsadapter.DB2DataStoreHelper
Connection timeout: 1800
Maximum connections: 40
Minimum connections: 1
Reap time: 180
Aged timeout: 0
Purge policy: EntirePool
Component-managed authentication alias: DB2 Administrator Alias

This last parameter it's defined this way:

Alias: DB2 Administrator Alias
User id: ****
Password: ****

Finally, I defined a JDNI alias to use the DataSource, with the next parameters, in web.xml:

Resource: TestDataSource
Type: javax.sql.DataSource
Authentication: Container
Sharing: Shareable

JNDI name: jdbc/TestDataSource

Then, I execute the following code:

try {
System.err.println("Accessing Data Source");

// Creamos un DataSource utilizando JNDI
Hashtable env = new Hashtable();
InitialContext ctx = new InitialContext(env);

javax.sql.DataSource myDS =
(javax.sql.DataSource) ctx.lookup("jdbc/TestDataSource");
// I also tried with "java:comp/env/TestDataSource"

this.connection = myDS.getConnection();
System.err.println("Connection OK");
} catch (SQLException e) {

In this code, everything seems to work, but I've never received the message "Connection OK", neither the stack trace of any exception, and the servlet that uses it throws this error: [ServletException in ublica/menu.jsp] null'

Anybody has an idea of what can happen to this code, or the server? I'm need this problem sorted shortly, or I'll kill myself
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following things you can check for-
1) Have you tested the whether the datasource is working fine using the "test connection" option in Administration console ?
2) Secondly if you are writing this code as a server side program which is going to run on the websphere server machine then just do the new InitialContext(). That would be sufficient.

// I also tried with "java:comp/env/TestDataSource"

, I think you should be using "java:comp/env/jdbc/TestDataSource" instead provided that your <res-ref-name> element in <resource-ref> has value "jdbc/TestDataSource".
hope this helps
    Bookmark Topic Watch Topic
  • New Topic