I want to get the selected value from JComboBox, search it in database and update the quantity in database with the value in JTextField. Here is the code :
Object selected = jComboBox1.getSelectedItem(); String album = (String)selected; int qty=Integer.parseInt(jTextField7.getText()); String query2="update productlist set QtyAvail=? " + "where Album=?"; try { PreparedStatement ps2=con.prepareStatement(query2); ps2.setInt(1, qty); ps2.setString(2,album); int res1=ps2.executeUpdate(); } catch(Exception e) { e.printStackTrace(); } I'm getting this error:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: " 1" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at AddProductPanel.jButton2ActionPerformed(AddProductPanel.java:341) at AddProductPanel.access$4(AddProductPanel.java:335) at AddProductPanel$5.actionPerformed(AddProductPanel.java:133) I entered value '1' in the text field.