Quantcast
Channel: VBForums - Java
Viewing all articles
Browse latest Browse all 54

com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint

$
0
0
Error on this line

Code:

int rowsAffected = statement.executeUpdate();
With this code

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();

Error.

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)

But as I see in my Management Studio that the data has been saved.but still getting this error ..why?

Viewing all articles
Browse latest Browse all 54

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>