File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes connecting to sql file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connecting to sql file" Watch "connecting to sql file" New topic
Author

connecting to sql file

Adam Confino
Ranch Hand

Joined: Sep 03, 2009
Posts: 48
Hey Java Gurus!

I am running a MySQL Community Server and receive the following error message:

Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/bedandbreakfast
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at SqlTest.main(SqlTest.java:19)

Here is my code:



I'm guessing it can't find the driver, but I'm not sure where to go from here. I have read JDBC Java trail and w3schools SQL tutorial, but am still stuck. Any help diagnosing what then wrong would be appreciated.

Thanks for your expertise,
Adam



Just Another Guy Hooked on Java
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You are right, the error message means the DriverManager cannot find a suitable driver on the classpath that can handle requests for that particular JDBC URL.

There is usually no good reason to use the JDBC-ODBC bridge and plenty good reasons not to. Try using a type 4 driver instead. Have a look at that and remember there are thtree steps to getting a connection this way:
  • The driver files must be on the classpath
  • You must have called Class.forName with the correct class name (this step will register the driver with the DriverManager)
  • You must be using the correct syntax in your URL. The documentation for the driver will help here.



  • JavaRanch FAQ HowToAskQuestionsOnJavaRanch
    Adam Confino
    Ranch Hand

    Joined: Sep 03, 2009
    Posts: 48
    Thanks. I downloaded a type four driver as you suggested. How do I make sure that it is on the classpath?
    Paul Sturrock
    Bartender

    Joined: Apr 14, 2004
    Posts: 10336

    Our FAQs have something on this here.
    Adam Confino
    Ranch Hand

    Joined: Sep 03, 2009
    Posts: 48
    Thanks I'll read over it.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: connecting to sql file