我java 1.8 但是我增加了rt.jar
DB(){try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dbf="E:\\大学\\数据库\\Text.accdb"; //连接一个access数据库
String dburl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb,*.accdb)};DBQ=" + dbf;
conn = DriverManager.getConnection(dburl,"","");
stmt = conn.createStatement();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
//
e.printStackTrace();
}
}
错误:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:436)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)