-1

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);
        }
  • Your SQL appears to contain column names with spaces in them (e.g. buying price.) Even if this is allowable it's hardly recommended practice. You would probably have to have put quotes around those column names in the SQL... – RBH Aug 26 '19 at 18:44
  • 1
    `no value specified for parameter 6` - The message is clear, you need to specify the 6th parameter `itemid` – Arnaud Claudel Aug 26 '19 at 22:17
  • Possible duplicate of [java.sql.SQLException: No value specified for parameter 2](https://stackoverflow.com/questions/26993563/java-sql-sqlexception-no-value-specified-for-parameter-2) – Markus Deibel Aug 27 '19 at 04:15

2 Answers2

0

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

You need set itemid as well.

Qingfei Yuan
  • 1,196
  • 1
  • 8
  • 12
0

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

Luno S
  • 46
  • 3