• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connection Pool

 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[/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
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please, subbu. I would like to have your sample code. Thanking you in advance
Beksy
 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
reply
    Bookmark Topic Watch Topic
  • New Topic