Link to home
Start Free TrialLog in
Avatar of PraKash
PraKash

asked on

Java connection to access database

I need to access a mdb database.
I tried using the JDBC-ODBC bridge connector. It keeps giving me "Class not found error"
Is there another way to do that or can someone tell me if there is an external jar file that I can use to fix this error?
Avatar of Mick Barry
Mick Barry
Flag of Australia image

can u post your current code
ASKER CERTIFIED SOLUTION
Avatar of edwardiii
edwardiii

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
String strDSN   = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=" + TestDB;
//testDB is your MDB Filename
Connection cnct = null;
Statement stmt  = null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cnct = DriverManager.getConnection(strDSN,"","");
stmt = cnct.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
rs.close();
stmt.close();
conn.close();
Avatar of PraKash
PraKash

ASKER

Hi.
I tried something similar to edwardii. But this is the error that I keep getting.
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver

I was also wondering if there was a different way of acecssing a mdb without the jdbc odbc bridge
Hi, PraKash.  If you're using the code in a Try/Catch structure, it should work.  Can you post the code you've got so far, as objects recommended?
Avatar of PraKash

ASKER

try{
  Class.forName("org.relique.jdbc.csv.CsvDriver");
     Connection conn = DriverManager.getConnection("jdbc:relique:csv:" + path );
      Statement stmt = conn.createStatement();
      ResultSet results = stmt.executeQuery("SELECT * FROM QUEUE");
  String url = "jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};" +
  "DBQ=C:\\example.mdb";
}

In the first statement itself it gives me that error.
Hi PraKash,

Did you include the csvjdbc.jar in the classpath?
Avatar of PraKash

ASKER

That was a bad example. I pulled the above code from a different project that I was working on. There is no external jar files included for this project.


try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            con = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=example.mdb","","");

Its errors out saying sun.jdbc.odbc.JdbcOdbcDriver not found.
Is there any external jar files that I have to include in the classpath?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree with pkwan, PraKash.  In fact, are you running this from an IDE, or are you building everything manually with a text editor from the command line?