Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sun ODBC driver

 
M Burke
Ranch Hand
Posts: 406
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
M Burke
Ranch Hand
Posts: 406
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 128
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic