thanks for the Idea I'm working on it. EDIT: I managed to do what I wanted BUT... It only happens till the application is open and I'm saving data one after one...as soon as I close to application and opens in again I have see the last file no and enter the next file no manually. with this code
String filenostr = filenotxtfield.getText();
statement.setString(1,filenostr);
int fileno=Integer.parseInt(filenostr);
fileno++;
String convertno=String.valueOf(fileno);
filenotxtfield.setText(convertno);
statement.executeUpdate();
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();
Addition to that I'm getting error on line
int rowsAffected = statement.executeUpdate();
ERROR:
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?