aspose file tools*
The moose likes JDBC and the fly likes cannot connect to database using JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "cannot connect to database using JNDI" Watch "cannot connect to database using JNDI" New topic
Author

cannot connect to database using JNDI

Dave Brown
Ranch Hand

Joined: Mar 08, 2005
Posts: 301
Hi All, This is quite a desperate cry, i've been trying to solve this problem now for over a day and a half, I've seen lots of other threads on google with the same issues and have have tried each solution I found but to no avail.

I cannot connect to my database using JNDI., the actual error is "DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'"

Quick Outline ; I tend to develop in netbeans 4, and then move the build over to another installation of tomcat for final testing before putting it on a live external server. The system works ok through netbeans IDE, but the tomcat 5.5.7 installation is not playing. I believe I ahve installed all the correct jar's for DBCP and Connector/J. In my common/lib folder there are the commons' jar's and also the mysql-connector-java-3.1.7-bin.jar file.

the MySql connector is also there in the web-inf/lib directory. I also have the jar listed in the classpath environment variable, so I cant see any problem in tomcat detecting the driver.

My Web.xml contains.....
<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/ez2000
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>

and the server.xml contains ...

<Resource
name="jdbc/ez2000"
type="javax.sql.DataSource"
password="ferret"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://localhost/ez2000"
maxActive="4"/>


within the GlobalNamingResources tag.

What else.. hmm the JSP which i'm using to test is very simple, I include the JSTL tag and am testing the connection with the line

<sql:query var="queryresults" dataSource="jdbc/ez2000">SELECT * from keys</sql:query>


I can connected directly to the database using the netbeans IDE database explorer. so that proves url i'm is correct. And when I log into the tomcat admin screen, the database section lists my jdbc/ez2000 connection which says to me server.xml entries are correct.

If anyone can help, has any advice its greatly appreciated.

Thanks.

[Bear edit: better subject]
[ March 17, 2005: Message edited by: Bear Bibeault ]

Regards, Dave Brown
SCJP 6 - [url]http://www.dbws.net/[/url] - Check out Grails Forum
Dave Brown
Ranch Hand

Joined: Mar 08, 2005
Posts: 301
FINALLY !!! I have solved the problems I was having...

After battling with config files, and reading and reading of various posts online to try and solve the problem, I came across one article which mentioned using the Tomcat Admin tool. I thought this was quite a basic utility, I never saw that you can expand the Service Node in the left frame of the page. It isnt immediately obvious, and sadly I never read the readme for the Admin module.

Anyway for anybody who has been having similar troubles, You can use the admin tool and not worry about adding correct entries in the various xml config files.

So 1. Set up the DBCP Pool Data Source under the Resources node and 2. ("After" deploying your app), expand the Service node, then Host, the the Context node for your App and then you will be able to add a Data Source which will tie together with the data source added under Resources by its JNDI name.

Well I hope this saves some poor soul some of the frustration and lack of productivity I have been having this past couple of days.

:-)
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30753
    
156

Dave,
Thanks for sharing the solution! I'm moving this to the Tomcat forum for filing.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot connect to database using JNDI