我正在尝试从我的 Java 应用程序连接到 MS Access 数据库。这是我的代码:
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// set this to a MS Access DB you have on your machine
String filename = "UserInformation.accdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
// now we can get the connection from the DriverManager
Connection con = DriverManager.getConnection( database ,"","");
Statement st= con.createStatement();
int i=st.executeUpdate("insert into Users(User_Name,User_Password) values('"+username+"','"+password+"')");
System.out.println("Row is added");
}catch (Exception e) {
System.out.println("Error: " + e);
}
我收到此异常:未找到数据源名称且未指定默认驱动程序 (ODBC)?
我该如何解决?
提前致谢