wood burning stoves 2.0*
The moose likes Servlets and the fly likes Connection Pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Connection Pool" Watch "Connection Pool" New topic
Author

Connection Pool

Beksy Kurian
Ranch Hand

Joined: Jul 11, 2001
Posts: 254
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
Siva Jagadeesan
Ranch Hand

Joined: Oct 31, 2000
Posts: 160
[/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

Rgds<p>--Siva Jagadeesan<br /><a href="http://java2simple.blog-city.com" target="_blank" rel="nofollow">http://java2simple.blog-city.com</a><br />Sun Certified Java2 Programmer<br />Sun Certified Web Component Developer<br />BEA Certified Weblogic Server 7 Enterprise Developer
Beksy Kurian
Ranch Hand

Joined: Jul 11, 2001
Posts: 254
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
Subbu Aswathanarayan
Ranch Hand

Joined: Jun 22, 2001
Posts: 73
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


Subbu
Beksy Kurian
Ranch Hand

Joined: Jul 11, 2001
Posts: 254
Please, subbu. I would like to have your sample code. Thanking you in advance
Beksy
Subbu Aswathanarayan
Ranch Hand

Joined: Jun 22, 2001
Posts: 73
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
Vedprakash Pathak
Greenhorn

Joined: Mar 06, 2001
Posts: 24
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Connection Pool