aspose file tools*
The moose likes Tomcat and the fly likes Configuring Tomcat 5.5.7 Data Source with MYSQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Configuring Tomcat 5.5.7 Data Source with MYSQL" Watch "Configuring Tomcat 5.5.7 Data Source with MYSQL" New topic
Author

Configuring Tomcat 5.5.7 Data Source with MYSQL

Roland gray
Greenhorn

Joined: Nov 28, 2004
Posts: 21
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

Joined: Nov 28, 2004
Posts: 21
Resolved!
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Configuring Tomcat 5.5.7 Data Source with MYSQL