You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by in...@projektinter.net on 2002/06/12 09:29:43 UTC
Problem JNDI DataSource - no Connection on MySQL DB
Hi,
trying to connect to my MySQL DB via JNDI but I do not get a Connection in detail:
Using Tomcat 4.03, Linux Suse 7.3, MySQL 3.23.14.
I try to connect with this code:
.
.
.
Context initCtx = new InitialContext();
if (initCtx == null) throw new JspException("No Context available for DataSource, can't get connetion");
Context envCtx = (Context) initCtx.lookup("java:comp/env");
if (envCtx == null) throw new SQLException("No DataSource availale for Connection (envCtx == null)");
ds = (DataSource)envCtx.lookup("jdbc/wwa-mDB");
if (ds == null) throw new SQLException("No DataSource availale for Connection (ds == null) " + ds + "envCtx = " + envCtx);
verbin = ds.getConnection();
verbin.setReadOnly(true);
stmt = verbin.createStatement();
.
.
an the problem ist that ds == null (envCtx == org.apache.naming.NamingContext@452200).
I am wondering why I cannot connect the DB. Before I connectet directly like:
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/wwa-m01?user=user&password=pwd";
And it worked just fine.
My web.xml-File lookes like:
<resource-ref>
<description>
Resource reference to a factory for java.sql.Connection
instances that may be used for talking to a particular
database that is configured in the server.xml file.
</description>
<res-ref-name>jdbc/wwa-mDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
und the server.xml:
<Resource name="jdbc/wwa-mDB" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/wwa-mDB">
<parameter><name>user</name><value>user</value></parameter>
<parameter><name>password</name><value>pwd</value></parameter>
<parameter><name>driverClassName</name><value>org.gjt.mm.mysql.Driver</value></parameter>
<parameter><name>url</name><value>jdbc:mysql://localhost:3306/wwa_m01</value></parameter>
</ResourceParams>
Can you give me any assistance on how to find out what is wrong with my Connection an how I can find out about that?
Thanks a lot!
Rainer