Results 1 to 1 of 1
Thread: Using JDBC-ODBC bridge
-
Using JDBC-ODBC bridge
Review the code below. It connects to the the database using JDBC-ODBC bridge.
Java Code:class JDBCapp { static Connection theConn; public static void main (String args[]) { try { // connection to an ACCESS MDB theConn = MyConnection.getConnection(); ResultSet rs; Statement stmt; String sql; sql = "select objet from Email"; stmt = theConn.createStatement(); rs = stmt.executeQuery(sql); while (rs.next()) { System.out.println(rs.getString("objet")); } rs.close(); stmt.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (theConn != null) theConn.close(); } catch (Exception e) { } } } } class MyConnection { public static Connection getConnection() throws Exception { Driver d = (Driver)Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); Connection c = DriverManager.getConnection( "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=c:/tech97.mdb" ); return c; /* To use an already defined ODBC Datasource : String URL = "jdbc:odbc:myDSN"; Connection c = DriverManager.getConnection(URL, "user", "pwd"); */ } }
Similar Threads
-
SWT & Swing Bridge problem
By roshithmca in forum AWT / SwingReplies: 0Last Post: 03-26-2008, 01:23 PM -
How to use JDBC Template classes to control basic JDBC processing and error handling
By JavaBean in forum Java TipReplies: 0Last Post: 09-28-2007, 12:56 PM -
Security Violation:attempt to use Restricted Class: sun.jdbc.odbc.JdbcOdbcDriver
By Heather in forum Advanced JavaReplies: 1Last Post: 07-14-2007, 05:59 PM -
without ODBC
By Heather in forum JDBCReplies: 2Last Post: 06-29-2007, 02:42 PM -
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
By Marcus in forum JDBCReplies: 1Last Post: 06-27-2007, 05:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks