tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Parsons Technical Services" <parsonstechni...@earthlink.net>
Subject Re: Question about JNDI resources
Date Wed, 19 Jan 2005 00:49:57 GMT
Since no one else has taken a crack at this....

As for the examples, a lot of apps do not hold any static content. At least 
simple example types. Then there is the issue of jsp's with no static class.

It sounds plausible to hold onto the DataSource once you had it. If you did, 
I don't think you would need to hold onto anything else. Sounds like a good 
experiment. I think the ultimate answer would be it depends, as this 
Interface could be implemented differently by different vendors. Then what 
is the overhead of holding that ref in comparison to doing the lookup. Sound 
like profiler time. And then there is an issue of synchronization?

Doug

----- Original Message ----- 
From: "Alan Deikman" <Alan.Deikman@znyx.com>
To: <tomcat-user@jakarta.apache.org>
Sent: Monday, January 17, 2005 1:42 PM
Subject: Question about JNDI resources


> 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
> connection");
>        try {
>            Context initContext = new InitialContext();
>            Context envContext  =
> (Context)initContext.lookup("java:/comp/env");
>            DataSource ds = (DataSource) envContext.lookup("jdbc/zzzz");
>            Connection conn = ds.getConnection();
>            return conn;
>        } catch (NamingException ne) {
>            System.out.println("User.getConnection caught Naming
> exception");
>            System.out.println(ne.toString());
>        } catch (SQLException sqle) {
>            System.out.println("User.getConnection caught SQL exception");
>            System.out.println(sqle.toString());
>        }
>
> 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: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message