import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class AccessTest {
public static void main(String[] args) throws Exception {
AccessTest ms = new AccessTest();
}
public AccessTest(){
try {
///加载驱动jar
Class.forName("com.hxtt.sql.access.AccessDriver").newInstance(); //其实你将Access_JDBC30拷贝到ext目录下就不用这段代码了
//指定Access数据库文件的位置
String url = "jdbc:Access:///d:/Access/Database2.mdb";
//建立连接
Connection conn = DriverManager.getConnection(url, "", "");
Statement sta = conn.createStatement();
String sqlStatement= "SELECT * FROM Table1";//Table1是你要查询的表的名字
ResultSet rs = sta.executeQuery(sqlStatement);
System.out.println("\n查找到的学生信息");
System.out.println("--------------------------");
while (rs.next()) {
System.out.println("编号:"+rs.getInt("ID")+",姓名:"+rs.getString("name")+",年龄:"+rs.getInt("age"));
}
}catch (Exception e) {
e.printStackTrace();
}
}
}