tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anish Tom Ashley <anish.ash...@tavant.com>
Subject Cannot create JDBC driver of class - help!!
Date Mon, 01 Aug 2005 15:29:37 GMT
Hi,
	I'm trying to create a struts based application which tries to
access MySQL dB using mysql-connector-java-3.1.10 connector.
	I'm having problem with my getConnection() code. The following error
is occurring.....

            org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC
driver of class ' ' for connect URL 'null'
                        at
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.jav
a:780)
                        at
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:5
40)
                        at
com.tavant.app1_2.dao.MySQLLoader.executeQuery(MySQLLoader.java:29)
                        at
com.tavant.app1_2.action.HomePageAction.execute(HomePageAction.java:28)
                        at
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProces
sor.java:419)
                        at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
                        at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
                        at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
		..........................etc....etc
	

	I've pasted the server.xml, web.xml and my java program only
including relevant parts.

	------------------------------------ server.xml
----------------------------------------------------------------
<?xml version='1.0' encoding='utf-8'?>
<Server>
  <context path="/teststruts" docBase="teststruts.war" debug="1"
reloadable="true"> 
    <Resource name="mydatasource" type="javax.sql.DataSource"/>
    <ResourceParams name="mydatasource">
      <parameter>
        <name>factory</name>
        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
      </parameter>
      <parameter>
        <name>maxWait</name>
        <value>5000</value>
      </parameter>
      <parameter>
        <name>maxActive</name>
        <value>4</value>
      </parameter>
      <parameter>
        <name>password</name>
        <value>f_695248</value>
      </parameter>
      <parameter>
        <name>url</name>
        <value>jdbc:mysql://localhost:3306/tavant</value>
      </parameter>
      <parameter>
        <name>driverClassName</name>
        <value>com.mysql.jdbc.Driver</value>
      </parameter>
      <parameter>
        <name>maxIdle</name>
        <value>2</value>
      </parameter>
      <parameter>
        <name>username</name>
        <value>root</value>
      </parameter>
    </ResourceParams>
  </context>  
</Server>
	
----------------------------------------------------------------------------
-----------------------------------------
	------------------------------------ web.xml
----------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app> 
 <resource-ref>
   <description>
    Resource reference to a factory for java.sql.Connection
    instances that may be used for talking to a particular
    database that is configured in the server.xml file.
   </description>
   <res-ref-name>mydatasource</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
 </resource-ref>
</web-app>
	
----------------------------------------------------------------------------
-----------------------------------------


	------------------------------------ MySQLLoader.java
----------------------------------------------------------------
package com.tavant.app1_2.dao;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class MySQLLoader {
	public void executeQuery() {
	        try {		  
		    InitialContext ctx = new InitialContext();
		    Context ctx2 = (Context)ctx.lookup("java:comp/env");

		    DataSource ds = (DataSource)ctx2.lookup("mydatasource");
        		    Connection conn = ds.getConnection();
               	    Statement stmt = conn.createStatement();
                            stmt.executeUpdate("Insert into customer
values('001','Anish','001')");
                            stmt.close();            		        
           		    conn.close();        	   
	         } catch(Exception e) {					
	         	//some code
	         } finally{
	         	//some code
                     }
}
	
----------------------------------------------------------------------------
-----------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message