File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Connection pooling not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Connection pooling not working" Watch "Connection pooling not working" New topic
Author

Connection pooling not working

saquib nisar
Greenhorn

Joined: Nov 13, 2000
Posts: 14
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

Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connection pooling not working