Reputation: 581
This is the error my program is giving. java.sql.SQLException: ORA-00001: unique constraint (SYSTEM.SYS_C006997) violated
I tried the following code still the error message in JOptionPane is not "User Exists" ..How can i do that? And also do i need to execute commit statement from my program to save the tables created in oracle db ?
try {
Statement stmt = con.createStatement();
stmt.executeUpdate("insert into users values('"+st1+"','"+st2+"')");
JOptionPane.showMessageDialog(null,"User Added","Message",JOptionPane.INFORMATION_MESSAGE);
setVisible(false);
src.addusr.main(null);
}
catch(SQLIntegrityConstraintViolationException e)
{
JOptionPane.showMessageDialog(null,"User Already Exists","Message",JOptionPane.ERROR_MESSAGE);
}
catch(SQLException e2) {
JOptionPane.showMessageDialog(null,e2.getMessage(),"Message",JOptionPane.ERROR_MESSAGE);
e2.printStackTrace();
}
try {
Statement stmt1 = con.createStatement();
stmt1.executeUpdate("commit");
}
catch(SQLException e6) {
e6.printStackTrace();
}
}
Upvotes: 0
Views: 4997
Reputation: 587
In that particular table you are applying the unique constraint named SYS_C006997. Check that particular column whether it is properly defined or not.
In Oracle there is no need to execute the auto_commit. By default all the oracle commands will be auto committed.
Upvotes: 0
Reputation: 4014
By default, all new connections obtained from DataSource are in auto-commit mode. This means that your insert statement is commited immediately.
If you observe constraint violation exception and you don't know which table this constraint is related you can see constraint details with this select:
select * from user_constraints where constraint_name='SYS_C006997'
Good luck.
Upvotes: 2