I spent some time in the afternoon, I realized the programming of Java & Access. In fact, it is a company that needs to integrate two heterogeneous systems. The database is a SQL Server using MS and the other is Access. In fact, for the operation of the data sheet, it is unable to always always an important step in the program. Previously, the company has been using SQL Server, the database access operation is made in JavaBean, and most companies are actually doing this.
In terms of programming, for SQL Server, Microsoft provides a special JDBC driver, which is the three JAR files that are usually used. But Access's programming is not so luxurious, now available programming methods, just provide a JDBC-ODBC bridge to connect, efficiency is not to say. The process is also slightly speaking: 1. Create a URL of the database: Configure the Access data source, such as: string url = "jdbc: odbc: oblog"; 2, load the driver class.forname ("Sun.jdbc.odbc. JDBCODBCDRIVER "); 3, create connection connection conn = driverManager.getConnection (URL," User "," PWD "); 4, create SQL statement object statement stmt = conn.createstatement (); 5, execute SQL statement Stmt.execute ( STRSQL.TOSTRING ()); Simply sticked example:
//Select.java import java.sql. *; Class select {public static void main () {Try {string URL = "JDBC: ODBC: Wombat"; connection conn = drivermanager.getConnection (URL, "User", "PWD "); Statement stmt = conn.createstatement (); resultset = stmt.executeQuery (" Select * from table1 "); system.out.println (" got resultset now "); rs.beforefirst (); while (RS." Next ()) {system.out.println (rs.getstring (1));} stmt.close (); conn.close ();} catch (exception ex) {ex.printstacktrace ();}}}