You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Nottebrok, Guido" <Gu...@t-systems.de> on 2001/10/22 12:21:08 UTC
MySQL Database and Tomcat 4.0.1
Hallo,
I try to use a MySQL database with tomcat4.0.1. and Windows2000 but no success.
The jdbc2_0-stdext.jar and mm.mysql-2.0.6.jar are in CATALINA_HOME\common\lib.
I read the jndi-resources-howto.html and searched in the list-archive but I get
always null for the DataSource or a NamingException.
Do I need the factory entry in server.xml ?
Is the correct type javax.sql.DataSource or org.gjt.mm.mysql.MysqlDataSource?
In some exampes I found auth="SERVLET". But in the documentation was written, that
the value must be "Container" or "Application". What do I have to put there?
Could somebody please send me an example for web.xml, server.xml and coding
or show me my mistakes.
Here is what I have, but this is not working.
----- server.xml -----
<Context path="/schulpartner"
docBase="schulpartner"
crossContext="false"
debug="0"
reloadable="true" >
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_schulpartner_log." suffix=".txt"
timestamp="true"/>
<!-- JNDI JDBC DataSource Resource for using MySQL dB -->
<Resource name="jdbc/mysqlDB" auth="SERVLET"
type="javax.sql.DataSource"/>
<!-- type="org.gjt.mm.mysql.MysqlDataSource"/> -->
<ResourceParams name="jdbc/mysqlDB">
<parameter><name>factory</name>
<value>org.gjt.mm.mysql.MysqlDataSourceFactory</value>
</parameter>
<parameter><name>user</name><value>name</value></parameter>
<parameter><name>password</name>pw<value></value></parameter>
<parameter><name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value></parameter>
<parameter><name>driverName</name>
<value>jdbc:mysql://localhost:3306/mysql</value>
</parameter>
</ResourceParams>
</Context>
----- server.xml -----
<resource-ref>
<description>
Datenbank LPM Schulpartnerschaften
</description>
<res-ref-name>jdbc/mysqlDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<!--<res-type>org.gjt.mm.mysql.MysqlDataSource</res-type> -->
<res-auth>Container</res-auth>
</resource-ref>
----- in my Servlet -----
DataSource ds = null;
//MysqlDataSource mds = null;
Context initCtx = null;
Context envCtx = null;
//IninitialContext anlegen
try
{
initCtx = new InitialContext();
}
catch (NamingException e)
{
log(" Konnte keinen InitialContext anlegen: " + e);
return;
}
try
{
envCtx = (Context) initCtx.lookup("java:comp/env");
}
catch (NamingException e)
{
log(" Konnte keinen Context für 'java:comp/env' anlegen: " + e);
return;
}
try
{
ds = (DataSource) envCtx.lookup("jdbc/mysqlDB");
//ds = (MysqlDataSource) envCtx.lookup("jdbc/mysqlDB");
log(" Datasource: "+ds);
}
catch (NamingException e)
{
log("lookup für 'jdbc/mysqlDB' fehlgeschlagen: " + e);
return;
}
Thanks in advance
Guido