Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No suitable driver found

 
chetan dhumane
Ranch Hand
Posts: 641
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting this exception

No suitable driver found for jdbc:mysql://localhost:3306/test?user=root;password=1234


I have also included MySQL Connector 5.1.7 driver And I am using JSP to get connection(from eclipse)

Thanks in advance
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chetan dhumane wrote:
No suitable driver found for jdbc:mysql://localhost:3306/test?user=root;password=1234


I have also included MySQL Connector 5.1.7 driver

Put those driver jar file on classpath.
chetan dhumane wrote:
And I am using JSP to get connection(from eclipse)

Bad practice, not recommended, why don't you use servlets ?
chetan dhumane wrote:
No suitable driver found-Urgent

http://faq.javaranch.com/java/EaseUp
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This topic is already been discussed more and more times in JDBC forum.. please use javaranch search utility before posting your query..

hope it helps.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Rohankar wrote:
Put those driver jar file on classpath.

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 plain wrong.

 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke Scholtz wrote:
You will get this exception when the driver isn't loaded at all,

And it isn't loaded at because they aren't on classpath to load.
Bauke Scholtz wrote:
or the JDBC URL is plain wrong.

Yep, you got it right, the URL is wrong. The JDBC parameter/properties are separated by "&" and not by ";"
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Rohankar wrote:
And it isn't loaded at because they aren't on classpath to load.

As said, that would rather produce a ClassNotFoundException.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke Scholtz wrote:
Sagar Rohankar wrote:
And it isn't loaded at because they aren't on classpath to load.

As said, that would rather produce a ClassNotFoundException.


Yes, ClassNotFoundException occurs in Class.forName() statement and not in when connecting to DB

No suitable driver found for jdbc:mysql://localhost:3306/test?user=root;password=1234
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I got it, thanks Bauke and Balu. But what are the possible reasons for Driver not getting loaded?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Though your intended Driver is in classpath , it will happen if your intended driver is not registered to DriverManager.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Rohankar wrote:OK, I got it, thanks Bauke and Balu. But what are the possible reasons for Driver not getting loaded?
It's either simply not loaded at all or he suppressed the exception.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Balu Sadhasivam wrote:
if your intended driver is not registered to DriverManager.

Right, when you say

then
When the method getConnection is called, the DriverManager will attempt to locate a suitable driver from amongst those loaded at initialization and those loaded explicitly using the same classloader as the current applet or application.(using Class.forName())

Crystal clear now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic