0
import java.sql.*;

public class connect { 
    public static void main(String[] args) {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
            Connection conn = DriverManager.getConnection("jdbc:odbc:connection_name");
            Statement st = conn.createStatement(); 
            String sql = "Select * from Currencies"; 
            ResultSet rs = st.executeQuery(sql); 
            while(rs.next()){ 
                System.out.println("\n"+rs.getString(1)+"\t"+rs.getString(2));
            }
        } 
        catch (Exception e) { 
            System.out.println("Exception: "+e.getMessage()); 
        } 
    }
}

I get the following output :

Exception: sun.jdbc.odbc.JdbcOdbcDriver

Any ideas?

Thank you

Njol
  • 3,000
  • 14
  • 31
  • Can you please provide the stacktrace aswell? – aexellent Jun 13 '17 at 16:06
  • java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at javaapplication1.connect.main(connect.java:13) – too_good_to_be_true Jun 13 '17 at 16:39
  • which java version do you use? check out this, if it's java 8 ;-) http://docs.oracle.com/javase/7/docs/technotes/guides/jdbc/bridge.html – aexellent Jun 14 '17 at 07:21

1 Answers1

-1

So Actually I did the following and worked just fine: 1. Downloaded from somewhere on youtube the files 1. hsqldb.jar 2. jackcess 2.0.4.jar 3. commons-lang-2.6.jar 4. commons-logging-1.1.1.jar 5. ucanaccess-2.0.8.jar

Then right click on the Java library and added as external JARs those JAR files.

and changed the code as :

import java.sql.*;

public class connect { public static void main(String[] args) {

try {
//  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:ucanaccess://C:/db1.accdb");
Statement st = conn.createStatement(); 
String sql = "Select * from test"; 
ResultSet rs = st.executeQuery(sql); 
while(rs.next()){ 
    System.out.println("\n"+rs.getString(1)+"\t"+rs.getString(2));

}
} 
catch (Exception e) { 
    System.out.println("Exception: "+e.getMessage()); 
} 

} }

the link for the youtube video is: https://www.youtube.com/watch?v=hwgWrznevzc

You can find the files on the description.