-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

Adam Michalik
  • 9,678
  • 13
  • 71
  • 102
  • 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](http://www.techonthenet.com/oracle/sequences.php) – Nitish Mar 09 '16 at 15:13

1 Answers1

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:

Community
  • 1
  • 1
Michael Broughton
  • 4,045
  • 14
  • 12