DB connection between Two servlets

Hi,

I have Two servlets, servlet1,servlet2.

In servlet1, I have written Connection Pooling using java class and In the INIT method I'm writing the database connection,

My Question is, How to use the same DB connection in servlet2 ?

here is my code (some portion) :

public class abc_internal extends HttpServlet

{ private ConnectionPool pool;

Statement stmt= null;

Statement stmt1= null;

Statement stmt2= null;

ResultSet abc = null;

ResultSet Name_Header= null;

private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

public void init(ServletConfig config) throws ServletException

{

try

{

pool = new ConnectionPool("oracle.jdbc.driver.OracleDriver","jdbc:oracle:thin:@IPADDRESS:1526:DB NAME","USERNAME","PASSWORD",5);

}catch(Exception e)

{

throw new UnavailableException("Couldn't create Connection Pool.....");

}

}

PLEASE Help me...

Thanks in advance.

[1036 byte] By [steve_martina] at [2007-11-27 2:39:47]
# 1

> Hi,

> I have Two servlets, servlet1,servlet2.

> n servlet1, I have written Connection Pooling using

> java class and In the INIT method I'm writing the

> database connection,

> My Question is, How to use the same DB connection in

> servlet2 ?

You don't.

Your database layer (DAO, POJO, EJB, etc) might pass connections around internally probably to maintain transactions. It would do that to accomplish a unit of work.

Servlets don't do that.

Servlets would use the database layer at different levels of granularity to accomplish any database activity.

jschella at 2007-7-12 3:02:03 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...