aspose file tools*
The moose likes JDBC 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
Bookmark "Sun ODBC driver" Watch "Sun ODBC driver" New topic
Author

Sun ODBC driver

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 388
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){

try{
//"sun.jdbc.odbc.JdbcOdbcDriver"
//"com.mysql.jdbc.Driver"
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
java.sql.Connection con;
con = DriverManager.getConnection("jdbc:mysql:///customer", "root", "");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select * from names");

while(rs.next()){
System.out.println(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3));
}

rs.close();
st.close();
con.close();


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

}
}
Paul Sturrock
Bartender

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: 388
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

Hi,

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
here

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: http://aspose.com/file-tools
 
subject: Sun ODBC driver