Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

WebSphere 3.5 Connectio pool ??

 
praveen p
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help me on how to create a DataSource in WebSphere 3.5 and how to use the connection pool provided by websphere in my stateless session beans. When I tried to look up the DataSource, using JNDI lookup, it gave a ClassCastException for com.ibm.ejs.ns.jndi.CNContextImpl. How I shall give the database URL when I create a DataSource, and pl help me in finding out why this exception is coming
Thanks & Rgds
Praveen
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your code and show us what exception you got...
Kyle
 
praveen p
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, The code segment which i used is the following.
public Connection getConnection() throws javax.ejb.EJBException, java.sql.SQLException {

InitialContext initCtx = null;
try {
initCtx = new InitialContext();
DataSource ds = (javax.sql.DataSource)initCtx.lookup("sba");
return ds.getConnection();
}catch(NamingException ne) {
System.out.println("Exception at getConnection() method in AttributeManagerBean class");
throw new EJBException(ne);
}finally {
try {
if(initCtx != null) initCtx.close();
}catch(NamingException ne) {
System.out.println("Error closing context: " + ne);
throw new EJBException(ne);
}
}
}
Here, 'sba' is the datasource name which is seen in the WebSphere admin console. I created a driver by name 'sba' and then installed it and created datasource. no the urlprefix is "jdbc b2"
Do I have to append the database server machine ip to this..? Please advice me whether my code is correct, and do I have to get an InitialContext object in the ejbCreate method.
In the above method, i tried to created an initial context in the following way too.
Properties h = new Properties();
h.put(javax.naming.Context.PROVIDER_URL,"iiop://localhost:900");
h.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
initCtx = new InitialContext(h);
When I try to use this getConnection() method from my servlet, its throwing the following exception(s)
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: com.ibm.ejs.container.UncheckedException: ; nested exception is: java.lang.ClassCastException: com.ibm.ejs.ns.jndi.CNContextImpl
Pl. do advice me how to proceed.
Thanks in advance
Praveen
 
ravindran shanmugam
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check whether you have included,
1) IBM Enterprise Extension Libraries and
2) IBM WebSphere Test Environment.
in your Class path ( preferably press "Select All" and include all in the class path.)
Second thing is try giving JNDI lookup name as

Regards
Ravindran.
[ February 19, 2002: Message edited by: ravindran shanmugam ]
 
kapil Gupta
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am also trying to use Connection Pooling using a simple java class in VAJ 3.5.
When I try to run the program, debugger opens with NoClassDefFoundError exception.
I am using the following code:-
javax.naming.InitialContext ctx =null;
javax.sql.DataSource ds =null;
Properties parms = new Properties();
try {
parms.put(Context.PROVIDER_URL,"iiop://localhost:900");
parms.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
ctx=new InitialContext(parms);
}
catch (Exception e) {
System.out.println("Exception= "+e);
}
try{
ds = (DataSource)ctx.lookup("jdbc/dbname");
Connection conn =ds.getConnection("scot","tiger");
}
catch (Exception e) {
System.out.println("Exception= "+e);
}
When I use the same code in a servlet, it runs fine. Can I use Connection pooling in simple class?
Regards,
kapil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic