It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes Sun ODBC driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Sun ODBC driver" Watch "Sun ODBC driver" New topic

Sun ODBC driver

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 397
When I run with using the Sun driver I get an error "MYSQL: java.sql.SQLException: No suitable driver"

I thought the Sun driver is universal and can be used by any ODBC database. Is MySql not an ODBC compliant database like DB2 and MS SQL7?

import java.sql.*;
public class DBTest{

public static void main(String[] args){

java.sql.Connection con;
con = DriverManager.getConnection("jdbc:mysql:///customer", "root", "");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select * from names");

System.out.println(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3));


} catch (SQLException se){
System.out.println("MYSQL: " + se);
} catch (Exception e) {
System.out.println("Excep : " + e);

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Your connection url could be wrong. When you use the DriverManager to get a connection all it does is traverses avaliable drivers to find one which suits the connection url you have supplied. If there isn't one then it won't try to make a connection.

One question though - why use an ODBC driver when there are JDBC drivers available for MySQL?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 397
I was just seeing if it will work. I can get it to work with the MySQL driver.

Ok, so when I use "sun.jdbc.odbc.JdbcOdbcDriver" it looks for an installed driver. Now I get it.

I want to be able to use JDBC to call DB2 and Oracle databases. Are there any instructions on how to do this?
Raj Chila
Ranch Hand

Joined: Mar 18, 2004
Posts: 128


well the ODBC Driver comes by default with the JDK and yes the error you are getting is probably because you still have to do the following...
To Use ODBC, means that the database is residing on the same machine as you are running the application. so you would probably need a DSN configured from the Control Panel.

This means that MySql should provide a ODBC Driver that you will be using to create this DSN, which you can download

Then you should also check with the Connection URL that you are providing...when you Use the ODBC Driver, then you the URL looks like this..

jdbc dbc:<the DSN Name that you create>

better still is to use the JDBC Driver which will help you avoid all this.
[ December 23, 2004: Message edited by: RajaniKanth Bhargava ]
I agree. Here's the link:
subject: Sun ODBC driver
It's not a secret anymore!