• 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

No Suitable Driver Found

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

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
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent Explanation Bauke
 
andrew bliss
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic