try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb);DBQ=d:/test.mdb");
Statement stmt=conn.createStatement();
int n=stmt.executeUpdate("insert into test (userName,userPwd) values('xpice','123456')");
System.out.println("n=" + n);
}catch(ClassNotFoundException e)
{
System.out.println(e.getMessage() );
}catch(SQLException e)
{
System.out.println(e.getMessage() );
}
运行后n=1
但是Access 没有更新
如果加上 这句ResultSet rs=stmt.executeQuery("select * from test");的话添加会成功!但为什么会这样呢?
但调试后得出的错误是:
ERROR:JDWP Unable to get JNI 1.2 environment ,jvm-> GetEvn() return =-2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):[../../../src/share/back/until.c:820]
解决:
1.加commit()试试;
2.Connection、PreparedStatement 没有关闭。
3.jdk版本不对,把jdk1.5改成1.6之后试试。