• 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

You've seen it a thousand times before... "SQLException: No suitable driver"

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would anyone be willing to suggest how to test this code? I'm not really sure for what DriverManager is looking.

Running JDeveloper, have included mysql-connector-java-5.1.7-bin.jar in the "libraries and classpath" window.


spits out
SQLException: No suitable driver found for jdbc:mysql://host/database
SQLState: 08001
VendorError: 0


The fact that I'm no longer getting a "Class strife" message gives me the impression that it has successfully found the Driver. I am able to connect to the database with SQLYog, so I think the database has no problems.

I'm planning on putting this on several computers, so putting it into .lib folders might be possible, but not ideal.

Suggestions?
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there,

I have a similar problem. I'm working with Netbeans and Tomcat (6.0.18), and it tells me that that it cannot find the Oracle driver (Oracle 11g oracle.jdbc.OracleDriver). For me it works pretty well when I load the driver by DriverManager, but when I want to create a connection pool by JNDI elements, Netbeans cannot detect the driver. Therefore Class.forName(oracle.jdbc.OracleDriver) throws the exception.

As I had setup my CLASSPATH properly (I had added both oracle and MySQL jar files to my CLASSPATH), I was curious to see what was the problem. It seems to me that it is a problem related to either tomcat or Netbeans. Because I created the following class (as a standalone application outside Netbeans, by using a simple text editor)




And when I compiled and run manually this program, I was surprised to see it prints: ""Yes the driver was detected""

Strange!!!

You will find thousands of threads on Sun forums about this problem! and unfortunately not a definitive answer that works for everybody
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Zachary,

you are using the correct driver name. So it has to be that you did *not* include mysql-connector-java-5.1.7-bin.jar to your runtime path in JDeveloper.

Note that your computer's classpath settings are not used by JDeveloper when it runs your project, and that you do not have to add the jar to the compile time classpath, but to the runtime classpath.


Please remove .newInstance() You don't have to instantiate the driver.

(note to self: on the other hand, when your jdbc driver is not on the runtime classpath, would that not have gotten this error: ClassNotFoundException ? )
 
Zachary Anderson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jan Cumps,
The first line when I tell it to run is,

C:\Oracle\Middleware\jdk160_05\bin\javaw.exe -client -classpath "C:\JDeveloper\mywork\myprogram\Project1\classes;C:\Documents and Settings\zanders\My Documents\myprogram 2.X\comm.jar;C:\Documents and Settings\zanders\My Documents\Project Program\driver\mysql-connector-java-5.1.7\mysql-connector-java-5.1.7-bin.jar" mywork.y


Given that "C:\Documents and Settings\zanders\My Documents\Project Program\driver\mysql-connector-java-5.1.7\mysql-connector-java-5.1.7-bin.jar" is part of that, it looks to me like it's in the runpath as well. Am I interpreting that correctly?

Thank you for the suggestion about newInstance, I have now removed it. I threw it in after reading on http://dev.mysql.com/doc/refman/5.1/en/connector-j-usagenotes-basic.html about
// The newInstance() call is a work around for some
// broken Java implementations

Thanks for your brains,
Zachary
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jan Cumps wrote:

(note to self: on the other hand, when your jdbc driver is not on the runtime classpath, would that not have gotten this error: ClassNotFoundException ? )



Thats exactly right. It would throw ClassNotFoundException.


Zachary,

The problem could be in this line. check for any misspelled characters or anything in jdbc URL string
 
Jan Cumps
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Zachary,

Given that "C:\Documents and Settings\zanders\My Documents\Project Program\driver\mysql-connector-java-5.1.7\mysql-connector-java-5.1.7-bin.jar" is part of that, it looks to me like it's in the runpath as well. Am I interpreting that correctly?

Yes. I thought from your original post that you were running it from JDeveloper.

Then we have the possible issue pointed out by Balu, though your url looks fine. The port number is not neededoiptional, so you should not have to use that.

Can you try, just to be sure, to use this approach - all fixed values for testing, please fill in correct host, port, database, user and password:

conn = DriverManager.getConnection("jdbc:mysql://XXXX:3306/XXXX?user=XXXX&password=XXXX");


Another thought:
Is it possible that C:\Oracle\Middleware\jdk160_05 is not your default java installation, and that you have

 
Zachary Anderson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jan Cumps,
I am indeed running it from JDeveloper. The first line in the "log window" (same place I get the results of my dummyprint statements) looks to be the call that JDeveloper makes to javaw.

I have switched out the previous getConnection statement with

and am getting
SQLException: No suitable driver found for jdbc:mysql://hostcomputer.workplace.here:3306/database?user=id&password=password

Am absolutely sure of hostcomputer.workplace.here, have compared it with the (successful) login with SQLYog.

As a bit of a head-check ( ) after reading up on DriverManager, I decided to see what Drivers were actually in the list.
I tried the code at http://java.sun.com/j2se/1.4.2/docs/api/java/util/Enumeration.html , but it looks like they have a bit of a mistake; since e is instantiated inside the start condition, it's not recognized in the body of the loop. Although that might be a JDeveloper mistake.

Anyways, running
gives me just
sun.jdbc.odbc.JdbcOdbcDriver@3e53cf
Does this mean I'm missing the driver I loaded, or is that a different name for it, or does the for-loop code miss the first item in the Enumeration?

Thanks again,
Zachary
 
dariyoosh za
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zachary Anderson wrote:Jan Cumps,
I am indeed running it from JDeveloper. The first line in the "log window" (same place I get the results of my dummyprint statements) looks to be the call that JDeveloper makes to javaw.

I have switched out the previous getConnection statement with

and am getting
SQLException: No suitable driver found for jdbc:mysql://hostcomputer.workplace.here:3306/database?user=id&password=password

Am absolutely sure of hostcomputer.workplace.here, have compared it with the (successful) login with SQLYog.

As a bit of a head-check ( ) after reading up on DriverManager, I decided to see what Drivers were actually in the list.
I tried the code at http://java.sun.com/j2se/1.4.2/docs/api/java/util/Enumeration.html , but it looks like they have a bit of a mistake; since e is instantiated inside the start condition, it's not recognized in the body of the loop. Although that might be a JDeveloper mistake.

Anyways, running
gives me just
sun.jdbc.odbc.JdbcOdbcDriver@3e53cf
Does this mean I'm missing the driver I loaded, or is that a different name for it, or does the for-loop code miss the first item in the Enumeration?

Thanks again,
Zachary




What is the web server you're using? Tomcat (if it is tomcat which version?).
 
Jan Cumps
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(I am blushing just by the tought of suggesting this -- don't laugh -- , but) can you put the Class.forName("... call outside the try ? Maybe some optimizer thingy doesn't think it's worth loading the class, because nothing realy happens inside the try block?

Here's what I mean -- attention, untested example:
 
Zachary Anderson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dariyoosh za: I'm not running a web application, so I'm not sure I understand your question. This is going to be distributed by passing around .jars.
Jan Cumps: Unfortunately, forName() throws an exception, and demands that it be caught.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zachary,
Did you try running standalone in command prompt. (without using NetBeans), Have CLASSPATH variable populated with "your mysql jar" or run java -cp "jarpath";. filename and check the output.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what's the answer? I'm getting this error too (among several others). I'm using WebSphere and CloudScape.

Zachary Anderson wrote:Would anyone be willing to suggest how to test this code? I'm not really sure for what DriverManager is looking.

Running JDeveloper, have included mysql-connector-java-5.1.7-bin.jar in the "libraries and classpath" window.


spits out
SQLException: No suitable driver found for jdbc:mysql://host/database
SQLState: 08001
VendorError: 0


The fact that I'm no longer getting a "Class strife" message gives me the impression that it has successfully found the Driver. I am able to connect to the database with SQLYog, so I think the database has no problems.

I'm planning on putting this on several computers, so putting it into .lib folders might be possible, but not ideal.

Suggestions?

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic