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