tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Liu, Abraham" <>
Subject Connection object question
Date Thu, 31 Jan 2002 14:58:08 GMT
Hi all,
Currently, we are developing a web site using jsp under Weblogic 5.1.
I have questions about how to create connection objects. Can anyone tell me
which method is the right way to do it?
(1) Using "Class.forName("weblogic.jdbc.pool.Driver")"  and 
    "con = DriverManager.getConnection("jdbc:weblogic:pool:db2Pool")" 
    to create a connection object for every query. We found out that if we
use this method, weblogic will intercept the connection call, and check
whether it has a available connection object in connection pool or not. If
it does, it throw back a connection object. Otherwise weblogic will generate
a connection object itself and increase the size of its connection pool then
return a connection object back. It seemed that Weblogic is in control all
the time. But this method is too slow to process query.
(2) Using datasource to access weblogic connection pool.
      The following stmts are being used,    
      Context ctx = null;

      String urll = "";
      Hashtable ht = new Hashtable();                           
      ht.put  (Context.INITIAL_CONTEXT_FACTORY,
      ht.put(Context.PROVIDER_URL, urll);
      ctx = new InitialContext(ht);
      javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("dsDB2");
      java.sql.Connection con = ds.getConnection();

      This method is much fast(I measured 4 times faster) to use to query
      But I still like to have someone to tell me that whether the second
method is the right    
      way to query database.

Another question I have is that after I open a connection object, when
shall I close it ?
For example, if I have 10 jsp programs and  each jsp requires 6 querys, do I
have to open connection object for every query and close it after the quey
finish. Or can I just open one conection object do all the querys in all 10
jsp programs, then close ?

Is any one can help me solve the puzzle. I will be appreciated.
Abe Liu        

To unsubscribe:   <>
For additional commands: <>
Troubles with the list: <>

View raw message