Hi!
I'm trying to create JNDI Datasource to a database in a Tomcat 5.5 environment. But I can't figure out how to do it. What am I doing wrong? I can access the database the normal way so it's nothing wrong with the database url and so.
I have put this in my context.xml:
maxActive="100" maxIdle="30" maxWait="10000"
username="" password="" driverClassName="com.hxtt.sql.access.AccessDriver"
url="jdbc:access:/e:/tmp/webtest.mdb"/>
In my web.xml I have this:
DB Connection
jdbc/dctest
javax.sql.DataSource
Container
And in a test servlet I use this:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/dctest");
Connection conn = ds.getConnection();
But I receive an exception:
Cannot create JDBC driver of class '' for connect URL 'null'
What's wrong?
Regards,
Fredrik Skånberg, Sweden
|
maxActive="100" maxIdle="30" maxWait="10000"
username="" password="" driverClassName="com.hxtt.sql.access.AccessDriver"
url="jdbc:access:///f:/mdbfiles/aaa.mdb"/>
jdbc/testAccessPool1
javax.sql.DataSource
Container
If it cannot work normal,please tell us your version of tomcat.
I tested upper config at tomcat 5.5.9 and it work normal.
|
<!--context.xml-->
<Resource name="jdbc/testAccessPool1" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="" password="" driverClassName="com.hxtt.sql.access.AccessDriver"
url="jdbc:access:///f:/mdbfiles/aaa.mdb"/>
<!--web.xml-->
<resource-ref>
<res-ref-name>jdbc/testAccessPool1</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
If it cannot work normal,please tell us your version of tomcat.
I tested upper config at tomcat 5.5.9 and it work normal.
|
Hi!
I still can't get it to work. I have tried it on Tomcat 5.5.12 and 5.5.16.
I copied your example and used this in a servlet:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/testAccessPool1");
Connection conn = ds.getConnection();
But when I run this I get this:
Cannot create JDBC driver of class '' for connect URL 'null'.
Where have you put Access_JDBC30.jar? In the applications WEB-INF/lib or in {Tomcat home}/common/lib or some place else?
/Fredrik
|
I use tomcat 5.5.16 to test and it work normal.
You should put the Access_JDBC30.jar to the ${TOMCAT_HOME}/common/lib or else it will throw cannot not find the driver class "com.hxtt.sql.access.AccessDriver" exception.
You can download the http://www.hxtt.com/test/WebApplication1.war and put it to ${TOMCAT_HOME}/webapps directory and restart tomcat.
If you can view data from http://localhost/WebApplication1/index.jsp,the configuration is correct.
If not,can you tell us your JDK version?
|
Hi!
Now it's working. It was two errors. I had put the context.xml file in the WEB-INF folder and not in the META-INF folder and my Context tag was written with a lower case, context. Realy bad error messages from Tomcat here.
But because of your little demo application I was able to solve this problem.
Thanks for excellent support!
/Fredrik
|