• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sun ODBC driver

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}

}
}
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 128
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Warning! Way too comfortable! Do not sit! Try reading this tiny ad instead:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic