Hi all
Thanks for yesterdays feedback. Following on I have done this:
Im now using inheritance to access javaexchange's connection broker as
per the brokers documentation. This is working as expected. So repeating
the question, in case you missed it - Can I guarentee that no user will
see the others results if the servlet is used in this way?
Thanks for the feedback and keep it coming, it's much appreciated!.
Steve
code:
import java.io.*;
import java.lang.StringBuffer;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
// DBInit extends HTTPServlet and holds connection pool
public class RepServlet extends DBInit
{
// simple test query
private String SQLQuery1 = "select prod_no, from myTable where
prod_no = ";
public void init ( ServletConfig config ) throws ServletException
{
super.init ( config );
}
public void doGet ( HttpServletRequest req, HttpServletResponse res )
throws ServletException, IOException
{
res.setContentType ( "text/html" );
ServletOutputStream out = res.getOutputStream ();
int product = Integer.parseInt (( req.getParameter ("product") ));
StringBuffer buf = new StringBuffer ();
buf.append ( "<HTML>\n<HEAD><TITLE>RepServlet</TITLE></HEAD>\n" );
buf.append ( "<BODY BGCOLOR='#ffffff' TEXT='#000000'>\n" );
// get a connection from the super class
// myBroker is the static instance of DBConnectionBroker
// should Connection be outside the method ?
Connection conn = null;
conn = myBroker.getConnection ();
Statement stmt = null;
try
{
stmt = conn.createStatement ();
if ( stmt.execute ( ( SQLQuery1 + product ) ) )
{
ResultSet rs = stmt.getResultSet ();
// Do table processing
}
else
{
buf.append ( "<B>Error</B>" );
}
}
catch ( SQLException e )
{
buf.append ( "<H1>ERROR:</H1> " + e.getMessage () );
}
finally
{
try
{
if ( stmt != null ) stmt.close (); // close statement
}
catch ( SQLException e )
{
buf.append ( "<H1>SQLException:</H1>" + e.getMessage () );
}
myBroker.freeConnection ( conn ); // release the connection
}
buf.append ( "</BODY>\n</HTML>" );
res.setContentLength ( buf.length () );
out.println ( buf.toString () );
out.flush ();
out.close ();
}
}
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html