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/17 14:02:51 UTC
Tomcat4.0 + JNDI + MySql
Hallo,
i have problems to get a MySql DataSource Object with JNDI in Tomcat 4.0.
The envCtx.lookup("jdbc/schulpartner") (see coding below) always returns null.
Tomcat and MySql are running and I can connect to the database directly (without Tomcat).
jdbc2_0-stdext.jar and mm.mysql-2.0.6.jar are in %CATALINA_HOME\common\lib
Here is a part of my Coding.
public class DatabaseControllerServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException
{
super.init(config);
DataSource ds = null;
//MysqlDataSource ds = null;
try
{
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (DataSource) envCtx.lookup("jdbc/schulpartner"); //returns null
//ds = (MysqlDataSource) envCtx.lookup("jdbc/schulpartner");
}
catch (NamingException e)
{
log("NamingException: " + e);
return;
}
. . .
}
Here is a part of my 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/schulpartner" auth="SERVLET"
type="javax.sql.DataSource"/>
<!-- type="org.gjt.mm.mysql.MysqlDataSource"/> -->
<ResourceParams name="jdbc/schulpartner">
<parameter><name>user</name><value></value></parameter>
<parameter><name>password</name><value></value></parameter>
<parameter><name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value></parameter>
<parameter><name>driverName</name>
<value>jdbc:mysql://localhost:3306/schulpartner</value>
</parameter>
<parameter><name>factory</name>
<value>org.gjt.mm.mysql.MysqlDataSourceFactory</value>
</parameter>
</ResourceParams>
</Context>
...
Here is a part of my web.xml
...
<servlet>
<servlet-name>DatabaseController</servlet-name>
<servlet-class>lpm.schulpartner.controller.DatabaseControllerServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
...
<resource-ref>
<description>
Datenbank LPM Schulpartnerschaften
</description>
<res-ref-name>jdbc/schulpartner</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>
...
Any hints...?
Guido Nottebrok