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?
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?
can u post your current code
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
String strDSN = "jdbc:odbc:driver={Microso ft Access Driver (*.mdb)};DBQ=" + TestDB;
//testDB is your MDB Filename
Connection cnct = null;
Statement stmt = null;
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
cnct = DriverManager.getConnectio n(strDSN," ","");
stmt = cnct.createStatement(Resul tSet.TYPE_ SCROLL_INS ENSITIVE, ResultSet.CONCUR_UPDATABLE );
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
rs.close();
stmt.close();
conn.close();
//testDB is your MDB Filename
Connection cnct = null;
Statement stmt = null;
Class.forName("sun.jdbc.od
cnct = DriverManager.getConnectio
stmt = cnct.createStatement(Resul
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
rs.close();
stmt.close();
conn.close();
ASKER
Hi.
I tried something similar to edwardii. But this is the error that I keep getting.
java.lang.ClassNotFoundExc eption: sun.jdbc.odbc.JdbcOdbcDriv er
I was also wondering if there was a different way of acecssing a mdb without the jdbc odbc bridge
I tried something similar to edwardii. But this is the error that I keep getting.
java.lang.ClassNotFoundExc
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?
ASKER
try{
Class.forName("org.relique .jdbc.csv. CsvDriver" );
Connection conn = DriverManager.getConnectio n("jdbc:re lique:csv: " + path );
Statement stmt = conn.createStatement();
ResultSet results = stmt.executeQuery("SELECT * FROM QUEUE");
String url = "jdbc:odbc:Driver={MicroSo ft Access Driver (*.mdb)};" +
"DBQ=C:\\example.mdb";
}
In the first statement itself it gives me that error.
Class.forName("org.relique
Connection conn = DriverManager.getConnectio
Statement stmt = conn.createStatement();
ResultSet results = stmt.executeQuery("SELECT * FROM QUEUE");
String url = "jdbc:odbc:Driver={MicroSo
"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?
Did you include the csvjdbc.jar in the classpath?
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.od bc.JdbcOdb cDriver");
con = DriverManager.getConnectio n("jdbc:od bc:Driver= {MicroSoft Access Driver (*.mdb)};DBQ=example.mdb", "","");
Its errors out saying sun.jdbc.odbc.JdbcOdbcDriv er not found.
Is there any external jar files that I have to include in the classpath?
try {
Class.forName("sun.jdbc.od
con = DriverManager.getConnectio
Its errors out saying sun.jdbc.odbc.JdbcOdbcDriv
Is there any external jar files that I have to include in the classpath?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?