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{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
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();
}
}
}
The actual pooling code can be found at:
http://www.earthweb.com/dlink.resource-jhtml.72.1395.|repository| |softwaredev|content|article|2000|06|20|SDdejongobpool|SDdejongobpool~xml.0.jhtml?cda=true Thanks for all your help.
Saquib