我正在尝试使用JDBC驱动程序在SQL Server上插入行。
查询在SQL Server上工作,我可以看到行。
然而,在我的代码中,我没有得到任何错误,但是行没有出现。
更奇怪的是,我的自动增量字段是递增的,也就是说,假设我的自动增量字段的值是3,我运行我的代码,什么也没有出现。我在SQLServer上运行查询,新行的值为5。
String query = "insert into SSSI_ADMIN.NBSIUSER(UserName,UserDomain) values('test4','domain4')";
Statement stmnt = null;
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
try {
Class.forName(driver);
String url = "jdbc:sqlserver://dt112654:1433;databaseName=SIBD;user=u;password=*****";
Connection conn = DriverManager.getConnection(url);
conn.setAutoCommit(false);
stmnt = conn.createStatement();
stmnt.execute(query);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if ( stmnt != null)
{
stmnt.close();
}
}你好,努诺。
发布于 2012-06-20 17:27:51
您没有提交您的更改。
您必须在stmnt.execute(query);之后调用conn.commit()
https://stackoverflow.com/questions/11116507
复制相似问题