曾经看到过一种最简单的连接access数据库的方法,居然不需要配置数据源,也不
需要安装驱动.今天看到网上有人问,就写下来了
======================================================================
import java.sql.*;
public class ToAccess {
public static void main(String args[]) {
try {
String url = "jdbc:odbc:driver={Microsoft
Access Driver (*.mdb)};DBQ=D:\\bookshop.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection
(url);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select *
from books");
while (rs.next()) {
System.out.println("The book's name
is:" + rs.getString("book"));
System.out.println("The author is: " +
rs.getString("author"));
}
rs.close();
stmt.close();
conn.close();
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
}