0

Hello I want to put 2 values to 2 columns in my table. I get those values from txtField and textField_1 (which are 2 textboxes on an GUI).

The problem is that whenever I push the button to register those values I get an syntax error on my mysql.

String query = "INSERT INTO Registration (Username , Password ) VALUES (? ,?)";
                java.sql.PreparedStatement pst = connection.prepareStatement(query);
                pst.setString(1,textField.getText());
                pst.setString(2,textField_1.getText());
                int rs = pst.executeUpdate(query);

If I put static values instead of ?, is working.

3

1 Answer 1

1
String query = "INSERT INTO Registration (Username , Password ) VALUES (? ,?)";
                java.sql.PreparedStatement pst = connection.prepareStatement(query);
                pst.setString(1,textField.getText());
                pst.setString(2,textField_1.getText());
                int rs = pst.executeUpdate();

use executeUpdate()

Sign up to request clarification or add additional context in comments.

1 Comment

This was it, I'll put it as an answer soon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.