Error on this line
With this code
Error.
But as I see in my Management Studio that the data has been saved.but still getting this error ..why?
Code:
int rowsAffected = statement.executeUpdate();
Code:
int rowsAffected = statement.executeUpdate();
if(rowsAffected > 0)
{
JOptionPane.showMessageDialog(null, "Data Inserted successfully!");
}
else
{
JOptionPane.showMessageDialog(null, "Data is not Inserted!", "Not successfully", JOptionPane.ERROR_MESSAGE);
}
statement.close();
con.close();
Code:
com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK__Employer__6F09E6800F975522'. Cannot insert duplicate key in object 'dbo.Employer'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:404)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:314)