Is Context not supposed to be within a Host element? You also have a lowercase 
"c" in <context rather than Context. You also will want jdbc/ before the name 
for the datasource. 

In fact, I think you need to read the manual (I am assuming Tomcat 5.0, 
otherwise look at your version).

http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html

Allistair.

> -----Original Message-----
> From: Anish Tom Ashley [mailto:[EMAIL PROTECTED]
> Sent: 01 August 2005 16:30
> To: tomcat-user@jakarta.apache.org
> Subject: Cannot create JDBC driver of class - help!!
> Importance: High
> 
> 
> 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(Basic
> DataSource.jav
> a:780)
>                         at
> org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDat
> aSource.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(RequestProce
> ssor.java:224)
>                         at
> org.apache.struts.action.ActionServlet.process(ActionServlet.j
> ava: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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


<FONT SIZE=1 FACE="VERDANA,ARIAL" COLOR=BLUE> 
-------------------------------------------------------
QAS Ltd.
Registered in England: No 2582055
Registered in Australia: No 082 851 474
-------------------------------------------------------
</FONT>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to