Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Configuring Tomcat 5.5.7 Data Source with MYSQL

 
Roland gray
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the following two errors when I try to configure a Data Source connection for Tomcat 5.5.7 and mysql

javax.naming.NameNotFoundException: Name jdbc:comp is not bound in this Context

java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester

Please refer to my server settings below. Can some one help?

Here is my "c:\tomcat\conf\server.xml" file
=============================================
<?xml version="1.0" encoding="UTF-8"?>
<Server>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<GlobalNamingResources>
<Environment
name="simpleValue"
type="java.lang.Integer"
value="30"/>
<Resource
auth="Container"
description="User database that can be updated and saved"
name="UserDatabase"
type="org.apache.catalina.UserDatabase"
pathname="conf/tomcat-users.xml"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
<Resource
name="jdbc/TestDB"
type="javax.sql.DataSource"
password="webapp"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="webapp"
url="jdbc:mysql://localhost:3306/test"
maxActive="4"/>
</GlobalNamingResources>
<Service
name="Catalina">
<Connector
port="8080"
redirectPort="8443">
</Connector>
<Connector
port="8009"
protocol="AJP/1.3"
protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"
redirectPort="8443">
</Connector>
<Engine
defaultHost="localhost"
name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
<Host
appBase="webapps"
name="localhost">
</Host>
</Engine>
</Service>
</Server>
==============================================


Here is the code which tries to used the datasource
==============================================
package util;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;

public final class TestSQL {

public static String check(String message) {
String name="";
try {
Connection conn = null;
Context ctx = new InitialContext();
if(ctx == null ) {
throw new Exception("Boom - No Context");
}
DataSource ds = (DataSource)ctx.lookup("jdbc:comp/env/jdbc/TestDB");
conn = ds.getConnection();
Statement stmt = conn.createStatement();
String query = "SELECT * FROM FORUMLIST";

ResultSet st = stmt.executeQuery(query);
while (st.next()) {
name += st.getString("Fourmid") ;
name += " "+ st.getString("ForumName");
name += " "+ st.getString("ForumBriefDesc") +"<BR>";
}

if (stmt != null) {
stmt.close();
}

if (conn != null) {
conn.close();
}

} catch (Exception e) {
e.printStackTrace();
}

return (name);

}

}

==============================================


Here are the entryst that I enter in the "Tomcat admin Form" to create the data source
==============================================

JNDI Name: jdbc/TestDB
Data Source URL: jdbc:mysql://localhost:3306/test
JDBC Driver Class: com.mysql.jdbc.Driver
User Name: web
Password: ******
Max. Active Connections: 2
Max. Idle Connections: 4
Max. Wait for Connection: 5000
Max. Wait for Connection:

[ February 08, 2005: Message edited by: Roland gray ]
[ February 08, 2005: Message edited by: Roland gray ]
 
Roland gray
Greenhorn
Posts: 21
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic