I’m trying to insert rows on SQL Server using a JDBC driver.
The query works on SQL Server and I can see the row.
However, in my code, I don’t get any error but the row doesn’t appear.
What is even weirder, my auto-increment field is incremented, i.e. let’s say my auto-increment field has value 3, I run my code, nothing appears. I run the query on SQLServer, the new row has value 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();
}
}
Regards,
Nuno.
You are not committing your change.
You have to call
conn.commit()afterstmnt.execute(query);