I have taken some connection pooling code from a website, which works when run stand-alone (i.e. not view a servlet), but fails when run through a servlet. I am posting the code here, to help you gain an idea of what is going on. Apologies in advance for the length of the post. // ConnectionPoolTest.java - this works import java.sql.*; public class ConnectionPoolTest {
public static void main(String args[]) { try { // establish database connection JDBCConnection mydb = new JDBCConnection("AxaDB"); // send SQL request to database mydb.sendRequest("SELECT name from SYSTEM.Branch WHERE name LIKE '" + "B" + "%'"); // get result set ResultSet rs = mydb.getRs(); // process result set while (rs.next()) System.out.println(rs.getString(1)); // release resources mydb.closeRequest(); } catch (Exception e) { e.printStackTrace(); } } } // ConnectionPoolTestS.java - this does not work import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; public class ConnectionPoolTestS extends HttpServlet{
Originally posted by saquib nisar: I have taken some connection pooling code from a website, which works when run stand-alone (i.e. not view a servlet), but fails when run through a servlet.
"Fails" as in... Works and returns data but doesn't pool? Appears to work but doesn't return any data? Throws an exception? What exception and stack trace? What servlet engine? Do you have any idea if your servlet was instantiated more than once?
saquib nisar
Greenhorn
Joined: Nov 13, 2000
Posts: 14
posted
0
Originally posted by Peter den Haan: "Fails" as in... Works and returns data but doesn't pool? Appears to work but doesn't return any data? Throws an exception? What exception and stack trace? What servlet engine? Do you have any idea if your servlet was instantiated more than once?
Peter, It raises an exception, in the following section of code: // send a request to the database public void sendRequest (String sqlString) throws SQLException, ClassNotFoundException, PoolException { if (inUse) closeRequest(); impl = connectionPool.acquireImpl(dbName); stmt = impl.getConnection().createStatement(); rs = stmt.executeQuery(sqlString); inUse = true; } The exception is on line impl = connectionPool.aq ... I am using Tomcat, integrated with Apache. I believe the error is something to do with not having a instance of the pool object available??? Thanks for your help. Saquib