Oracle 10g自动递增序列出错

时间:2016-03-09 14:44:42

标签: java oracle

我在Oracle 10g中创建了一个序列,因为我必须增加case_number字段auto_incremently。但是我收到了错误。

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 个答案:

答案 0 :(得分:0)

表中的字段不会自动填充,因为您已定义了序列。您必须在insert语句中引用sequence.nextval以插入值,或者向表中添加触发器以从序列中填充列。

有关示例,请参阅this post