tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Deikman <>
Subject Question about JNDI resources
Date Fri, 14 Jan 2005 21:56:57 GMT
I'm just learning this stuff, but having good success so far.  In my 
SQL-backed bean I use a JDBCResource as per the documentation:

protected static Connection getConnection() {
        //System.out.println("User.getConnection Attempting to get 
        try {
            Context initContext = new InitialContext();
            Context envContext  = 
            DataSource ds = (DataSource) envContext.lookup("jdbc/zzzz");
            Connection conn = ds.getConnection();
            return conn;
        } catch (NamingException ne) {
            System.out.println("User.getConnection caught Naming 
        } catch (SQLException sqle) {
            System.out.println("User.getConnection caught SQL exception");

This works, way cool.  My question is do I need to look up two new 
Context objects and a new DataSource each time I get a connection?  Or 
can I just store initContext, envContext, and ds in static variables and 
load them just once for all instances of the class?

If that works, why don't the examples do it that way?

Alan Deikman
ZNYX Networks

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message