Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connecting to sql file

 
Adam Confino
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


  •  
    Adam Confino
    Ranch Hand
    Posts: 48
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks. I downloaded a type four driver as you suggested. How do I make sure that it is on the classpath?
     
    Paul Sturrock
    Bartender
    Posts: 10336
    Eclipse IDE Hibernate Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Our FAQs have something on this here.
     
    Adam Confino
    Ranch Hand
    Posts: 48
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks I'll read over it.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic