您尚未正确安装MSAccess驱动程序。
例如,尝试这样。
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // set this to a MS Access DB you have on your machine
String filename = "d:/DB.accdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;}"; // add on to the end
// Now we can get the connection from the DriverManager
Connection con = DriverManager.getConnection( database ,"","");
并确保在路径中已导入ODBC驱动程序的jar文件。
更新 :
像这样插入数据。
PreparedStatement pstmt = (PreparedStatement) con.prepareStatement("insert into product(productID,description,quantity,price,discount) values(?,?,?,?,?)");
pstmt.setString(1, productId);
pstmt.setString(1, desc);
//same for all statement
pstmt.executeUpdate();
pstmt.close();