Forums Register Login

Connection Pool

+Pie Number of slices to send: Send
Hi,
I was trying out the marty hall's connection pool. http://archive.coreservlets.com/coreservlets/ConnectionPool.java
I am getting a NullPointer Exeception when I try to get a connection. When I try to debug suing System.out messages, the first message before getting the conneection displays but the second one doesn't(after the getconnection method). Could anybody help me?
Part of my code is this...
public class LoginServlet extends HttpServlet {

private ConnectionPool connectionPool;


public void init() throws ServletException {

try {

int vendor = DriverUtilities.ORACLE;
String driver = DriverUtilities.getDriver(vendor);
String host = "hostname";
String dbName = "dbname";
String url = DriverUtilities.makeURL(host, dbName, vendor);
connectionPool =
new ConnectionPool(driver, url,"user", "password",
initialConnections(),
maxConnections(),
true);
}
catch(SQLException sqle) {
System.err.println("Error making pool: " + sqle);
getServletContext().log("Error making pool: " + sqle);
connectionPool = null;
}
}

public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String pageID=request.getParameter("pageID");
ResultSet myRs=null;
Statement myStmt=null;
String user = request.getParameter("userName");
String pass = request.getParameter("password");
String userName = user.toUpperCase();
String password = pass.toUpperCase();
boolean userExists = false;
String retrievedPassword = null;
String fname=null;
PrintWriter out = response.getWriter();
try{
System.out.println("testmessage1");
Connection connection = connectionPool.getConnection();
System.out.println("testmessage2");
myStmt = connection.createStatement();
String userSql="SELECT f_name,l_name,userid,passwd FROM customer_ref WHERE userid " + userName ";
myRs = myStmt.executeQuery(userSql);

if (myRs.next()) {
retrievedPassword = myRs.getString(4);
userExists = true;
}

}catch(Exception e)
{
System.out.println(e);
}

thanks
Beksy
+Pie Number of slices to send: Send
[/B]
String host = "hostname";
String dbName = "dbname";
String url = DriverUtilities.makeURL(host, dbName, vendor);
[/B]
I think the host and dbName are
wrong . chk it . The probelm must be the ConnectionPool is not getting any connections
try to give some debug msgs in the ConnectionPool class and chk
Siva
+Pie Number of slices to send: Send
I am giving the correct hostname, driver,url,username,password in the actual program. I tried to give some debug messages in the connection pool class, it is not even going inside the getconnection method. the system.out.message which I put as the first line in the getconnection method did not display.
without connection pooling this servlet works fine. I want to try out the connection pooling to make it efficient.
help! please
thanks
Beksy
+Pie Number of slices to send: Send
Hi beksy,
if you are trying out connection pool, i would greatly reccomend DBConnectionBroker(www.javaexchange.com).its pretty simple and i have got desired results.
if u want i can even send u my sample code.
Subbu
+Pie Number of slices to send: Send
Please, subbu. I would like to have your sample code. Thanking you in advance
Beksy
+Pie Number of slices to send: Send
 

Originally posted by Beksy Kurian:
Please, subbu. I would like to have your sample code. Thanking you in advance
Beksy


Hi Beksy,
I am sorry but I wasn't able to locate my file which uses dbConnectionBroker.anyway here is the link to the dbConnectionBroker zip file.this conatins an example java file which is very good and easy to understand.
ftp://javaexchange.com/javaexchange/DbConnectionBroker1.0.11.zip
i am sorry again.
Subbu
+Pie Number of slices to send: Send
Also there is another open source software to create connection pool at
www.codestudio.com

I am implemeting this at my work.. and works pretty well. Most of the bugs are fixed in the latest release.Also it has the examples to demonstrate the use.

I personally dont like DBConnectionBroker as there hsa been no change in the code for a long time (just my personal opinion)
I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 846 times.
Similar Threads
Maintaining scalability in servlets programming
404 error. Can't find resource?
How to use DBCP with JNDI ?
Running servlet from bean
How can we read initparameter(String t) of a servlet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:59:58.