This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
posted
0
Post your code and show us what exception you got... Kyle
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
posted
0
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
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