-2

I created a sequence in Oracle 10g because I have to increase case_number field auto_incremently. But I'm getting an error.

private void button_saveandsubmitActionPerformed(java.awt.event.ActionEvent evt) { con = JavaConnectDB.ConnectDB(); try{ String sql="insert into FIR_form values(case_number_sequence,?,?,?,?,?,?,?,?,?,?,?)"; pst = (OraclePreparedStatement) con.prepareStatement(sql); pst.setString(1,text_date.getText()); pst.setString(2,text_district.getText()); pst.setString(3,text_subject.getText()); pst.setString(4,text_description.getText()); pst.setString(5,text_cfullname.getText()); pst.setString(6,text_fhname.getText()); pst.setString(7,text_caddress.getText()); pst.setString(8,text_contact.getText()); pst.setString(9,text_suspectfullname.getText()); pst.setString(10,text_suspectaddress.getText()); pst.setString(11,text_suspectdescription.getText()); rs = (OracleResultSet) pst.executeQuery(); if(rs.next()){ JOptionPane.showMessageDialog(null, "the FIR has been added successfully!!!"); con.close(); this.dispose(); } else{ JOptionPane.showMessageDialog(null, "enter all fields appropriately first!!!"); } con.close(); }catch(Exception e){ JOptionPane.showMessageDialog(null, "An error occured. try again later !!!"); } } 

enter image description here

enter image description here

1
  • If case_number_sequence is your oracle sequence, you need to use case_number_sequence.NEXTVAL to retrieve the next value in the sequence order. Please refer to Simple Sequence Tutorial Commented Mar 9, 2016 at 15:13

1 Answer 1

0

The field in the table will not auto-populate because you have defined a sequence. You must either reference the sequence.nextval in your insert statement to insert the value, or add a trigger to the table to populate the column from the sequence.

See this post for an example:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.