Tomcat - DataSource Exception

M

Martin Huber

Hello,

i have a problem. I am using Tomcat 4.0 and MySql as database. I want
using the database connection pooling mechanism in Tomcat, but I have
problems.

If I test the connection, I get following error message:

TyrexDataSourceFactory: Cannot create DataSource, Exception
java.lang.NoClassDefFoundError: tyrex/jdbc/xa/EnabledDataSource
at org.apache.naming.factory.TyrexDataSourceFactory.getObjectInstance(Ty
rexDataSourceFactory.java:163)
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:165)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:301)
..
..
..
A problem occurred while retrieving a DataSource object
javax.naming.NamingException: Exception creating DataSource:
tyrex/jdbc/xa/EnabledDataSource


So, I have searched in different groups, but I did not found any
solution for my problem. I have enclosed my sourcecode. Maybe someone
can help me.

Thank you very much

Martin Huber

P.S. Sorry for my english...


Code in DatabaseManager.java (Servlet):
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (DataSource) envCtx.lookup("jdbc/DatabaseManager");
con = ds.getConnection();
Statement stmt = con.createStatement();
System.out.println("executed lookup for jdbx. JON");
}
catch (javax.naming.NamingException e){
System.out.println("A problem occurred while retrieving a DataSource
object");
System.out.println(e.toString());
}



Settings in server.xml:

<Context path="/DatabaseManager"
docBase="DatabaseManager"
debug="1"
reloadable="true"
crossContext="false">

<Resource name="jdbc/DatabaseManager"
auth="SERVLET"
type="javax.sql.DataSource" />

<ResourceParams name="jdbc/DatabaseManager">


<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>

<parameter>
<name>url</name>
<value>jdbc:mysql:///bfdr</value>
</parameter>

<parameter>
<name>username</name>
<value></value>
</parameter>

<parameter>
<name>password</name>
<value></value>
</parameter>

<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>

<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>

<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>

<parameter>
<name>testOnBorrow</name>
<value>true</value>
</parameter>

<parameter>
<name>testOnIdle</name>
<value>true</value>
</parameter>

<parameter>
<name>validationQuery</name>
<value>select current_date</value>
</parameter>

</ResourceParams>
</Context>




Settings in web.xml:

<resource-ref>
<description>
BFD-Regensburg
</description>
<res-ref-name>
jdbc/DatabaseManager
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
SERVLET
</res-auth>
</resource-ref>
 
N

NKV

Have you included the relavant jar/classes in TomCat's classpath. You
can put them in the lib directory under TomCat.
 
M

MikL

Martin Huber said:
Hello,

i have a problem. I am using Tomcat 4.0 and MySql as database. I want
using the database connection pooling mechanism in Tomcat, but I have
problems.

If I test the connection, I get following error message:

TyrexDataSourceFactory: Cannot create DataSource, Exception
java.lang.NoClassDefFoundError: tyrex/jdbc/xa/EnabledDataSource
at org.apache.naming.factory.TyrexDataSourceFactory.getObjectInstance(Ty
org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.
java:165)
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:301)
.
.
.
A problem occurred while retrieving a DataSource object
javax.naming.NamingException: Exception creating DataSource:
tyrex/jdbc/xa/EnabledDataSource

Martin,

An approach I have found useful is to first try to get a connection without
JNDI using the lower-level DriverManager.getConnection(url,user,password)
method. This will prove whether your driver classes are on CLASSPATH, and
that the database is accessible.

NB. Do this within a TRY-CATCH that catches and reports all _Throwables_ --
one trick I found here is that some driver errors are not Exception
subclasses -- they're Errors.

HTH,
MikL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top