aspose file tools*
The moose likes JDBC and the fly likes No Suitable Driver Found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "No Suitable Driver Found" Watch "No Suitable Driver Found" New topic
Author

No Suitable Driver Found

andrew bliss
Greenhorn

Joined: Dec 09, 2008
Posts: 12
Hello,

I am trying to get a jsp page to run a SQL query on it. When I run the page it comes up with an error saying No Suitable Driver Found.
I am using a conext.xml and a web.xml file to define a Datasource. It works on my other computer which is running windows. But this page is on an ubuntu server. I put the mysql-connector-java-5.1.7-bin.jar in the /usr/share/tomcat6/lib folder. I also put it in the WEB-INF/lib directory. I wrote a java application that uses the same connection string and it works just fine. It errors on this line

<sql:query var="rs" dataSource="jdbc/TestDB">

The URL is
http://www.hitlessons.com/DBtest/test.jsp

Context file

<?xml version="1.0" encoding="UTF-8"?>

<Context path="/DBtest" docBase="DBtest"
debug="5" reloadable="true" crossContext="true">

<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="****" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/testdb?autoReconnect=true"/>

</Context>

Do I need to change the path or something?

Thanks for any help
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

andrew bliss wrote: I put the mysql-connector-java-5.1.7-bin.jar in the /usr/share/tomcat6/lib folder.



put it under tomcat6/common/ lib folder
andrew bliss
Greenhorn

Joined: Dec 09, 2008
Posts: 12
I have tried that. First there is no common folder so I created one, put it in there and it still came up with the same error.
I have been looking around to see if how it checks the class path, I haven't found anything on that yet. Is there some way to set the classpath?

Thanks for the reply.

Ok so I made a new page that doesn't use the context file for the database source.

<sql:setDataSource
var="datasource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/ghetto"
user="root"
password="*****" />


<sql:query var="rs" dataSource="${datasource}">
select userid, username, password from users
</sql:query>

It didn't work at first. I googled around and found this page.

http://webui.sourcelabs.com/ubuntu/mail/user/threads/Tomcat_connecting_to_MySQL_-_Ubuntu_8.10_Server.meta

It said to turn TOMCAT_SECURITY to no. I did that and my new page works now. But my old one that uses the context.xml doesn't.
Is this the best thing to do? I didn't have to do this on my windows machine.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
seetharaman venkatasamy wrote:
andrew bliss wrote: I put the mysql-connector-java-5.1.7-bin.jar in the /usr/share/tomcat6/lib folder.



put it under tomcat6/common/ lib folder

That path only applies to Tomcat versions before 6.x only (thus, 5.5 and older).

Tomcat6/lib is the right path to place JAR's which are to be covered by the appserver's classpath.

Back to the actual problem: this is certainly not a classpath issue, you would get a ClassNotFoundException otherwise, not a SQLException with the message "No suitable driver". You will get this exception when the driver isn't loaded at all, or the JDBC URL is wrong.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Excellent Explanation Bauke
andrew bliss
Greenhorn

Joined: Dec 09, 2008
Posts: 12
So my one page is working without the context file. I had to turn off the TOMCAT_SECURITY.
Then my other page that uses the context file still says No Suitable Driver found, it has the exact URL.
Could it be that it isn't locating the context file? I put it in the META-INF dir under the DBtest dir where all the files are.
andrew bliss
Greenhorn

Joined: Dec 09, 2008
Posts: 12
I don't have any clue. I followed the HowTo

http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html

It works on windows XP, but not on ubuntu. Does anyone have any ideas? Thanks for the help

It works if I write a Java program. It works if I use

<sql:setDataSource
var="datasource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest"
user="javauser"
password="javadude" />


<sql:query var="rs" dataSource="${datasource}">
select id, foo, bar from testdata
</sql:query>

But it doesn't work if I define the Database in a context file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: No Suitable Driver Found