tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sean Dockery" <s...@sbdconsultants.com>
Subject RE: Datasource and connection
Date Mon, 03 Feb 2003 18:25:31 GMT
I'm curious as to why you're asking this question.  You should be using the
connection pool according to the documentation provided, because that is how
it is intended to be used.  That is...

void doPost(...)
{
  InitialContext ic = new InitialContext();
  Context jdbcCtx = (Context) ic.lookup("java:comp/env");
  DataSource ds = (DataSource) jdbcCtx.lookup("jdbc/myDataSource");

  Connection conn = null;
  Statement stmt = null;
  ResultSet rs = null;

  try {
    conn = ds.getConnection();

    stmt = ...

    rs = ...
  }
  catch(SQLException esql) {
  }
  finally {
    if(rs != null)
      rs.close();

    if(stmt != null)
      stmt.close();

    if(conn != null)
      conn.close();
  }
}

What exactly are you THINKING of doing?

-----Original Message-----
From: Lindomar [mailto:lindomar.silva@bol.com.br]
Sent: Monday, February 03, 2003 06:02
To: Tomcat Users List
Subject: Datasource and connection


Hi everybody!

I'm using datasource of tomcat for get connection.
Well, when i do this:
...
DataSource ds = (DataSource)ctx.lookup( "java:comp/env/jdbc/Anything");
if (ds != null)
    connection = ds.getConnection();
...

In the next time, will give tomcat  to me a new connection or the same?

I think that is same, but i didn't read anything about this.

And when Tomcat close this connection? Only through the timeout?

Thanks in advanced.




---------------------------------------------------------------------
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