java连接access老是出错
先贴上正确的代码
String ur1 = "jdbc:odbc:Driver={Microsoft Access Driver(*.mdb)};DBQ=D:\\JAVA\\workspace\\MobileSchedule\\Schedule.mdb"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection(ur1, "", ""); Statement sql = con.createStatement(); String sqlStr = "insert into Schedule values(" + year + ", " + month + " ," + day + " ," + hour + ", " + minter + ", " + timeout + ",'" + data + "')"; System.out.println(sqlStr); sql.executeUpdate(sqlStr); con.close();
|
需要注意的问题:
1. 需要在控制面板=>管理工具=>数据源(ODBC)=>用户DSN中插入MS Access Database数据源
2.插入更新删除要选择sql.executeUpdate,而不要选择sql.executeQuery…
仅当提醒!!!!