I'm having trouble connecting to MySQL using JNDI with Tomcat. I have
deleted my server.xml and started with a fresh copy. First, I made sure I
could connect to MySQL with a regular JDBC connection. Next, I added a
JDBC Realm using MySQL. That works fine. Finally, I added a JDBC resource
and tried to use it. That is when I get the error below.
The error I have, and have always had, even before the 4.1 detour, is the
following:
javax.naming.NamingException: Exception creating DataSource:
org.hsql.jdbcDriver
at org.apache.naming.NamingContext.lookup(NamingContext.java:842)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:183)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at foo.DBTest1.init(DBTest1.java:19)
at org.apache.jsp.DbTest1$jsp._jspService(DbTest1$jsp.java:60)
Why would Tomcat be looking for a Hypersonic SQL driver? I took a shot and
copied Hypersonic 1.61 hsqldb.jar to /common/lib, but when it had no effect
I removed it.
I'm currently running
Windows 2000
J2SE 1.4.0
J2SE 1.3.1
Tomcat 4.04
MySQL 4.0.2-Alpha
MySQL Connector 2.0.14. (I copied mysql-connector-java-2.0.14-bin.jar to
$TOMCAT_HOME/common/lib,)
I get the same error no matter what code I run. For example, Both code
blocks below result in the same error:
Context ctx = new InitialContext();
ctx.addToEnvironment(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
Connection conn = ds.getConnection();
if(ctx == null )
throw new Exception("Boom - No Context");
DataSource ds = (DataSource)ctx.lookup(
"java:comp/env/jdbc/TestDB"); <-- Blows up here
--- AND ---
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
if(envCtx == null )
throw new Exception("Boom - No Context");
DataSource ds =
(DataSource)envCtx.lookup("jdbc/TestDB"); <--- Blows up here
I added the following to the web.xml file:
<resource-ref id="ResourceRef_TestDB">
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Here is my server.xml file:
<Server port="8005" shutdown="SHUTDOWN" debug="0">
<Service name="Tomcat-Standalone">
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector className="org.apache.catalina.connector.http.HttpConnector"
port="8080" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="10" debug="0" connectionTimeout="60000"/>
<!-- Define the top level container in our container hierarchy -->
<Engine name="Standalone" defaultHost="localhost" debug="0">
<!-- Global logger unless overridden at lower levels -->
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="catalina_log." suffix=".txt"
timestamp="true"/>
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
driverName="org.gjt.mm.mysql.Driver"
connectionURL
="jdbc:mysql://localhost/authority?user=javauser;password=javadude"
userTable="users" userNameCol="user_name" userCredCol
="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />
<!-- Define the default virtual host -->
<Host name="localhost" debug="0" appBase="webapps" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix
=".txt"
pattern="common"/>
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs" prefix="localhost_log." suffix=".txt"
timestamp="true"/>
<!-- Tomcat Root Context -->
<!--
<Context path="" docBase="ROOT" debug="0"/>
-->
<!-- Tomcat Manager Context -->
<Context path="/manager" docBase="manager"
debug="0" privileged="true"/>
<!-- Security Test -->
<Context path="/stewart" docBase="stewart" debug="0"
reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_examples_log." suffix=".txt"
timestamp="true"/>
<Manager className
="org.apache.catalina.session.PersistentManager"
debug="0"
saveOnRestart="true"
maxActiveSessions="-1"
minIdleSwap="-1"
maxIdleSwap="-1"
maxIdleBackup="-1">
<Store className="org.apache.catalina.session.FileStore"/>
</Manager>
</Context>
<!-- Test JDBC to MySql -->
<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_DBTest_log." suffix=".txt"
timestamp="true"/>
<Resource name="jdbc/TestDB"
auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/TestDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30000</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>100</value>
</parameter>
<parameter>
<name>username</name>
<value>javauser</value>
</parameter>
<parameter>
<name>password</name>
<value>javadude</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/javatest</value>
</parameter>
</ResourceParams>
</Context>
</Host>
</Engine>
</Service>
<!-- Define an Apache-Connector Service -->
<Service name="Tomcat-Apache">
<Connector className="org.apache.catalina.connector.warp.WarpConnector"
port="8008" minProcessors="5" maxProcessors="75"
enableLookups="true"
acceptCount="10" debug="0"/>
<!-- Replace "localhost" with what your Apache "ServerName" is set to
-->
<Engine className="org.apache.catalina.connector.warp.WarpEngine"
name="Apache" defaultHost="localhost" debug="0" appBase="webapps">
<!-- Global logger unless overridden at lower levels -->
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="apache_log." suffix=".txt"
timestamp="true"/>
<!-- Because this Realm is here, an instance will be shared globally
-->
<Realm className="org.apache.catalina.realm.MemoryRealm" />
</Engine>
</Service>
</Server>
Any ideas?
Steve Mitchell
e-Business Architect/Developer
Integrated Corporate Solutions, Inc.
913-685-6506
[EMAIL PROTECTED]
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php