JDBC DataSource error with Commons DBCP
843836Oct 1 2004 — edited Oct 4 2004Hi Experts,
I am implementing connection pooling in my JSP page using the Commons DBCP.
I am using Tomcat 4.1.29
My JARs are :
commons-dbcp-1.1.jar
commons-pool-1.1.jar
commons-collections.jar
which I have placed in TOMCAT_HOME/common/lib/
My JSPs are in a directory TOMCAT_HOME/webapps/Pools/
My CLASSPATHS are also appropriately set.
Here r the parameters in the server.xml which I have in TOMCAT_HOME/conf/ :
<Context path="/Pools/servlet" docBase="Pools" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/test_dsn" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/test_dsn">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name> <!-- To set maximum number of active users -->
<value>3</value> <!-- 0 is for no limit -->
</parameter>
<parameter>
<name>maxIdle</name> <!-- Set maximum number of idle connections retained in the pool -->
<value>0</value> <!-- 0 is for no limit -->
</parameter>
<parameter>
<name>maxWait</name> <!-- Maximum time(ms) to wait for a dB connection available -->
<value>2000</value> <!-- Set -1 to wait indefinitely : here 10 seconds. -->
</parameter>
<!-- MySQL dB username and passwords -->
<parameter>
<name>username</name>
<value>root</value>
<name>password</name>
<value></value>
</parameter>
<!-- Class name for mm.mysql JDBC driver -->
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>
<!-- JDBC connection url for the MySQL Database -->
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost/omamconsultants_com?autoreconnect=true</value>
</parameter>
<parameter>
<name>returnAbandoned</name> <!-- Return an abandoned connection back to the pool -->
<value>true</value>
</parameter>
<parameter>
<name>returnAbandonedTimeout</name> <!-- Time to wait before an abandoned connection... -->
<value>30</value> <!-- ...is returned to the pool -->
</parameter>
</ResourceParams>
</Context>
<!-- ********************************************************* -->
and here's the JSP code in which I implement the connection pooling code :
<%@ page import="java.io.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.naming.Context"%>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="javax.sql.DataSource"%>
<%
Context ctx;
DataSource ds;
Connection con1;
Statement stmt;
ResultSet rs;
String SQL;
String mymailid="";
String mydomain="";
try
{
System.out.println("\n\nCreating the Context...");
ctx = new InitialContext();
System.out.println("Context " + ctx + " created.");
if (ctx == null)
{
throw new Exception("No Context !!");
}
System.out.println("\nSearching for the DataSource...");
ds = (DataSource)ctx.lookup("java:comp/env/jdbc/test_dsn");
System.out.println("DataSource " + ds + " found.");
System.out.println("DataSource Name : java:comp/env/jdbc/test_dsn");
System.out.println("\nActivating the Pool for connections...");
if (ds != null)
{
System.out.println("Establishing the connection...");
con1 = ds.getConnection();
System.out.println("Obtained " + con1);
if (con1 != null)
{
System.out.println("Connection established.");
stmt = con1.createStatement();
SQL = "SELECT * FROM t_sherbir";
rs = stmt.executeQuery(SQL);
while (rs.next())
{
mymailid=rs.getString(1);
mydomain=rs.getString(2);
System.out.println(mymailid + "@" + mydomain);
}
}
else
{
System.out.println("The Connection could not be established !!");
}
System.out.println("Closing connection " + con1 + "...");
con1.close();
System.out.println("Connection closed.");
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
and this is the error that I get when I run the JSP :
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'n
ull', cause:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:243)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:743)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:518)
at org.apache.jsp.poolConnectionTest_jsp._jspService(poolConnectionTest_jsp.java:101)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j
ava:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Standar
dPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Standar
dPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Standar
dPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Standar
dPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Standar
dPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Standar
dPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11P
rotocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Thread.java:536)
Can any1 help me ? Where am I going wrong ?