I've tried out the connection pooling. Unfortunately, I'm getting an error which impede my progress.
Am using local host and Ms Access to test out.
Here's my xml in Context.xml:
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlnssi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<Context>
<!-- Specify a JDBC datasource -->
<Resource name="jdbc/odbc:abcODBC1" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.jdbc.odbc.JdbcOdbcDriver"
url="jdbcdbc://localhost:3306/pract1"
maxActive="10" maxIdle="4" />
</Context>
And my DoPost Servlet:
public class ProcessRegistration extends HttpServlet { private DataSource dataSource; private Connection conn; private Statement stmt; DataSource pool; @Override public void init() throws ServletException { try { // Get DataSource Context initContext = new InitialContext(); pool = (DataSource) initContext.lookup("java:/comp/env/abcODBC1"); if (pool == null) { throw new ServletException("Unknown DataSource 'jdbc/abcODBC1'"); } } catch (NamingException e) { e.printStackTrace(); } } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); conn = null; ResultSet rs = null; PreparedStatement ps = null; stmt = null; try { conn = pool.getConnection(); stmt = conn.createStatement(); // inserting records into database ----- } catch (SQLException ex) { Logger.getLogger(ProcessRegistration.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (rs != null) { rs.close(); rs = null; } if (stmt != null) { stmt.close(); stmt = null; } if (conn != null) { conn.close(); conn = null; } } catch (SQLException e) { throw new ServletException("Servlet records", e); } } out.close(); } }
The error message from Tomcat is :
javax.naming.NameNotFoundException: Name abcODBC1 is not bound in this Context at org.apache.naming.NamingContext.lookup(NamingConte xt.java:770)
Hope someone can reply this ...really cos am not getting reply from my other questions.....