Hi Guys,

I am getting an error:

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "jLabel4"

With this code:

        public void insertCustomer() {
            Properties conProps = new Properties();
          conProps.setProperty("user", "user");
        conProps.setProperty("password", "pass");
         int q = Integer.parseInt(jLabel4.getText());

     try {
             con = DriverManager.getConnection("jdbc:mysql://", conProps);
            } catch (SQLException ex) {
                Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex);

            String sql = ("INSERT INTO order_prty(customer, barcode, total) VALUES (?,?, ?)");

            try {


                st = (com.mysql.jdbc.PreparedStatement) con.prepareStatement(sql);
               st.setString(1, customer.getSelectedItem().toString());
                 st.setString(2, jTextField3.getText().toString());
              //  JOptionPane.showMessageDialog(null, "saved!");

            } catch (Exception se) {

Any ideas?

Greetings london-G!
Try putting a breakpoint at line 5 and then running the debugger to see what value you're getting for jLabel4. If it's not a string (i.e. - text) or if it's null, then that will help you find a solution. :)


TekknoDraykko: maybe you should re-check the error message.
The actual text he is trying to parse into a number is: "jLabel4", that is what the exception message says.

longon-G: most likely, you wanted to put a jTextField there, instead of a JLabel, since a JLabel is not really used for input.

     int q = Integer.parseInt(jLabel4.getText());

There is your problem. this line is basically:

     int q = Integer.parseInt("jLabel4");

and since "jLabel4" is not a numerical value which can be parsed to an int, you get that error. make sure you try to parse the text of the correct field and only when it has a valid value.

Thanks Guys,

As advised, I changed it to a textfield and set it a value. It worked!

Yep, my mistake. I mistook the string for a JLabel control (guess I should slow down when reading these ;) ).

Good job london-G.