简体   繁体   English

整数不会设置为JTextField

[英]Integer won't set into JTextField

I'm having problems in my program. 我的程序有问题。 Well, here's my code: 好吧,这是我的代码:

    JButton btnAdd = new JButton("Add");
    btnAdd.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) { 
            try{
                String query = "INSERT INTO GuestList (id, Title, FirstName, MiddleName, LastName, Address, ContactNo, Occupation) values (?, ?, ?, ?, ?, ?, ?, ?)";
                PreparedStatement pst = conn.prepareStatement(query);
                count++;

                pst.setString(1, String.valueOf(textField.setText(count + "")); //<<--This is my problem
                pst.setString(2, comboBox.getToolTipText());
                pst.setString(3, fNameTextField.getText());
                pst.setString(4, mNameTextField.getText());
                pst.setString(5, lNameTextField.getText());
                pst.setString(6, addressTextPane.getText());
                pst.setString(7, contactNoTextField.getText());
                pst.setString(8, occupationTextField.getText());
                pst.execute();

                JOptionPane.showMessageDialog(null, "Data Saved!");

                pst.close();

            }catch(Exception e){

            }

        }
    });

I'm having an auto increment in the line that has a comment in it. 我在其中有注释的行中有一个自动增量。 It says that " - Syntax error, insert ")" to complete Expression" and "The method valueOf(Object) in the type String is not applicable for the arguments (void)" 它说“-语法错误,插入“)”以完成表达式”和“字符串类型中的方法valueOf(Object)不适用于参数(void)”

What should I do to get rid of these? 我应该怎么做才能摆脱这些? Can someone help me? 有人能帮我吗? Thank you. 谢谢。 :) :)

for every opening group like this ( you will need a closing one like that ) 对于每个这样的开放组您将需要一个这样的封闭组

you have here 3 open and 2 closed.... 您这里有3个开放和2个封闭....

 pst.setString(1, String.valueOf(textField.setText(count + ""));

so you are missing one ) 所以你想念一个

try: 尝试:

pst.setString(1, String.valueOf(textField.setText(count + "")));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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