由于JDK8把ODBC驱动删除了,因此连接access等一些数据库时需要手动下载驱动,这里一起贴上来
public class AccessConnectTest {
private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd mm:ss");
public static void main(String[] args) {
System.out.println("start connect");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:ABCD";
Connection con = DriverManager.getConnection(url, "", "");
Statement sta = con.createStatement();
ResultSet rst = sta.executeQuery("SELECT * FROM YOURTABLE;");
if(rst.next()){
System.out.println("记录时间:" + df.format(rst.getDate("LOGTIME")));
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("closed connect");
}
}
1