简体   繁体   中英

java.sql.SQLException :no value specified for parameter 6

when press update button it shows:

"java.sql.SQLException:parameter out of range(1>number of parameters,which is 0)".

 private void updateActionPerformed(java.awt.event.ActionEvent evt) {                                               
        try{
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/smakdb","root","kisal400");    
        String sql="Update itemk set name=?,type=?, buying price=?, selling price=?,description=? where itemid=?";
        pst=conn.prepareStatement(sql);

        pst.setString(1, name2.getText());
            String value=type2.getSelectedItem().toString();
                pst.setString(2,value);
        pst.setDouble(3,Double.parseDouble(buying2.getText()));
        pst.setDouble(4,Double.parseDouble(selling2.getText()));
        pst.setString(5,descript2.getText());

        pst.executeUpdate();
        JOptionPane.showMessageDialog(null, "updated!!!");
        conn.close();

        }catch(Exception e){

             JOptionPane.showMessageDialog(null, e);
        }

You have 6 question mark in the query, why not set the 6th parameter value?

You need set itemid as well.

In String sql you have six parameters "?" and once set five parameters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM