How to call connection pool servlet from another servlet?
843859Oct 31 2005 — edited Oct 31 2005I have created this servlet shown below for creating a connection pool. I now want to be able
to use this pool to provide my other servlets with a database connection, so I am attempting
to use a line like this to create the connection:
Connection ocon = ConPoolInit.getConnection("java:comp/env/jdbc/CraigsList");
But it does not compile. Can somebody help me with this code? Any suggestions are
greatly appreciated.
Here is the connection pool servlet:
*****************************
package CraigsClasses;
import javax.servlet.*;
import javax.servlet.jsp.*;
import java.net.*;
import java.io.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
public class ConPoolInit extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public static Connection getConnection(String lookup) throws NamingException, SQLException {
Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup(lookup);
Connection ocon = ds.getConnection();
context.close();
return ocon;
} // private Connection getConnection(String lookup) throws NamingException, SQLException {
} // public class ConPoolInit extends HttpServlet {
=========================================================