File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Websphere and the fly likes WebSphere 3.5 Connectio pool ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "WebSphere 3.5 Connectio pool ??" Watch "WebSphere 3.5 Connectio pool ??" New topic
Author

WebSphere 3.5 Connectio pool ??

praveen p
Greenhorn

Joined: Feb 13, 2002
Posts: 2
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

Joined: Aug 10, 2001
Posts: 3879
Post your code and show us what exception you got...
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
praveen p
Greenhorn

Joined: Feb 13, 2002
Posts: 2
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

Joined: Aug 30, 2001
Posts: 15
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

Joined: Jan 31, 2002
Posts: 9
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: WebSphere 3.5 Connectio pool ??
 
Similar Threads
Problem creating datasource in Websphere Test Environment
Remote JNDI Look up
create DataSource
Websphere 4.0 DB connectivity using lookup
How to access DataSource in Java Files