aspose file tools*
The moose likes JDBC and the fly likes Cannot create JDBC driver   Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Cannot create JDBC driver   " Watch "Cannot create JDBC driver   " New topic
Author

Cannot create JDBC driver

Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
Have MySQL server 4.1 running, tomcat 5.5.1 running. Here's my java class for testing the connection:




web.xml:



test.jsp:



part of modified server.xml:





I created a database called bird with MySQL, and the jsp file is placed in the folder webapps/jbird/, the Connect.class, web.xml and server.xml all sit at their right places. All necessary jar files(commons-dbcp-1.2.1.jar, commons-collections-3.1.jar ....) are correctly placed. And I not only tried rebooting the tomcat but also rebooted my laptop....but, miserably enough, always no connection and the information in the log file is:

INFO: Server startup in 4640 ms
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:780)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at com.chinabird.library.Connect.init(Connect.java:37)
at org.apache.jsp.connect_jsp._jspService(org.apache.jsp.connect_jsp:50)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:302)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:246)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
....
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773)
... 22 more


I've wasted way too much time on this issue, any suggestion or explaination would be greatly appreciated! Thank you very much in advance.


Regards,
Ellen
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
This is not something I've done before and I'm very interested to see how it all hangs together. My suggestion is to try the JNDI lookup without the "java:comp/env/" prefix - I don't see it anywhere else in your set-up.

If that fails and no one with greater experience than I pops up to help then I suggest that you work through the Tomcat example app provided with DBCP (I assume there is one) and see if you can get that working. Then look at the differences between the two.

Jules
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
I could not find anything out of place (after doing a quick review).

However, the stack trace suggests that the mysql driver classes are not in the classpath (Caused by: java.sql.SQLException: No suitable driver).

We use classes12.zip for oracle, i think its mysqlxxxx.jar for mysql. Check if the jar is present, if not, you can place the jar in shared/lib so that it can be used by all web applications.

[Edit]
Julian was right, apache has documentation on DataSource Configuration
The documentation talks about using a new driver "com.mysql.jdbc.Driver"

Hope this helps.
[ September 12, 2004: Message edited by: Sheldon Fernandes ]
Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
well I changed the org.gjt.mm.mysql.Driver to com.mysql.jdbc.Driver, put the
mysql-connector-java-3.0.15-ga-bin.jar into both common/lib and webapps/jbird/WEB-INF/lib, rebooted tomcat. No luck.
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
The ResourceParams tag is missing the name attribute.

<ResourceParams name="jdbc/CellphoneDB">

The parameters configured were thus not linked to the <Resource name="jdbc/CellphoneDB" ... />

That's why the error:
Cannot create JDBC driver of class '' for connect URL 'null'
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61656
    
  67

Moving to JDBC.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
Hi Sheldon,

I tried your treatment but it didn't work out. I found a better example here and I've given up this approach, and restored the original server.xml file. But still I'm eager to know why the code above always generated the same exceptions.

I'll be greatly obliged for any enlightenment.



Regards,
Ellen
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
Hi Ellen,

My previous answer was based on the Tomcat documentation for version 4.1 (this is what I use, sorry for not noticing the version you are using). I just had a look at the documentation for version 5.5 and it appears they have changed the server.xml structure. <ResourceParams> is no longer present. They have made all the configuration parameters as attributes of the <Resource> tag.

Have a look at the DataSource Configuration for Tomcat 5.5.

I hope this resolves your problem.

About the other approach, I have never used or seen that being done before. The conventional thing to do is to create DataSources (provided by application server) and perform a jndi lookup to get a reference to them.

Sheldon
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot create JDBC driver