Thanks, I will search the archives, ...you gave my an idea, it seems to
me I could use the following code in my bean and call the getMatches()
and forward the results to a ResultsPage.jsp.
TIA Tom K.
try{
Context env = (Context) new
InitialContext().lookup("java:comp/env");
pool = (DataSource) env.lookup("jdbc/myApp");
if (pool == null)
throw new ServletException("`jdbc/myApp' is an unknown
DataSource");
}catch (NamingException e) {
throw new ServletException(e);
}
public int getMatches(){
try {
/** Run prepared statement */
dbConnection = pool.getConnection();
PreparedStatement pstmt =
dbConnection.prepareStatement(Display_Statement_AdInfoView);
pstmt.setString(1,uniqueDateId);
pstmt.setString(2,titlePage
pstmt.setString(3,color);
pstmt.setString(4,banner);
pstmt.setBlob(5,myAppSays01);
pstmt.setString(6,phone);
pstmt.setString(7,email);
pstmt.setString(8,webSite);
rs = pstmt.executeQuery();
rs.last();
rowCount = rs.getRow();
dbConnection.close();
-----Original Message-----
From: Shapira, Yoav [mailto:[EMAIL PROTECTED]
Sent: Monday, March 22, 2004 1:42 PM
To: Tomcat Users List
Subject: RE: Database connection going from servlet to a bean
Hi,
>Mike thanks for the feedback, but is this the practical solution? For
>example, I am using a connection pool, the init is only done once, the
>bean does the processing, after the processing it done (that is the
>beans "set" their properties) the results are forwarded to another jsp
>for viewing, so where do I release my connection back into the pool?
Your question is a good argument for having the bean retrieve the
connection, do its processing, and release the connection. The results
you're forwarding can't be a java.sql.ResultSet, as that keeps the
connection open, but some other object containing the processed results.
Hand-in-hand with this approach goes the practice of getting a handle to
your connection pool in a ServletContextListener. The listener can make
a getConnectionPool() or getConnection() method available for use by
your beans. This approach has several advantages over the servlet init
(or jspInit for a JSP) design, all of which have been discussed in the
past on this list so if you're interested you can search the archives.
Yoav Shapira
This e-mail, including any attachments, is a confidential business
communication, and may contain information that is confidential,
proprietary and/or privileged. This e-mail is intended only for the
individual(s) to whom it is addressed, and may not be saved, copied,
printed, disclosed or used by anyone else. If you are not the(an)
intended recipient, please immediately delete this e-mail from your
computer system and notify the sender. Thank you.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.557 / Virus Database: 349 - Release Date: 12/30/2003
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.557 / Virus Database: 349 - Release Date: 12/30/2003
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]