Title: RE: [JBoss-user] jndi question
Here is all you need:
 
   Connection connection = ((DataSource)new InitialContext().lookup("java:comp/env/jdbc/MySqlDS")).getConnection();
 
Note the first part of that.  Don't use java:/MySqlDS.  That binds you directly to a datasource, limiting portability.  Instead, you lookup a "logical" representation, then map the logical to a physical in the deployment desriptors.  See the documentation for a complete example.

----- Original Message -----
From: Jim
Sent: Monday, June 03, 2002 7:11 PM
Subject: [JBoss-user] connection pools, connecting to database.

Alright, after much searching I still haven't been able to get database access working correctly.
 
I am trying to access a database from a stateless session bean.  For performance, I would like the connections to be pooled.  In JBoss2.4.4, this involved setting up a few mbeans in the jboss.jcml file.
 
This is my old code, that does not work.  Casting exceptino on the (ConnectionPoolDataSource).  What should I cast it as?  Is my entire approach wrong?  Any tips or pointers to documentation I may have missed would be very much appreciated.
 
  try{
      InitialContext ctx = new InitialContext();
      System.out.println(ctx.lookup("java:/MySqlDS").toString());
      ConnectionPoolDataSource cpds =
        (ConnectionPoolDataSource)ctx.lookup("java:/MySqlDS");
       
 
      PooledConnection pc = cpds.getPooledConnection();
      conn = pc.getConnection();
    }catch(Exception e){
      System.out.println("Exception occured in Auth.ejbCreate()");
      System.out.println(e.toString());
     
    }
 
Thanks,

Jim
 

Reply via email to