This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection pooling not working

 
saquib nisar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic