• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

cannot connect to database using JNDI

 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

:-)
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave,
Thanks for sharing the solution! I'm moving this to the Tomcat forum for filing.
reply
    Bookmark Topic Watch Topic
  • New Topic