0

I get syntax error to mysql insert statement. May I know how to correct this error ?

user=txtuser.getText();
      char[] pass=jPasswordField1.getPassword();
             String passString=new String(pass);
            try{                
                Connection con = createConnection();               
                Statement st = con.createStatement();


**String sql = "INSERT INTO login(username,Password)"+"VALUES"+"('"user"','"passString"')";**
 st.executeUpdate(sql);
            }
            catch(Exception e){
                JOptionPane.showMessageDialog(null,"Exception: "+ e.toString());
            }
1
  • What does this have to do with jQuery? Retagging now. Commented Jan 10, 2013 at 12:01

1 Answer 1

7

You're missing a few + operators:

String sql = "INSERT INTO login(username,Password) VALUES ('" + user + "','" + passString + "')";

Consider using PreparedStatement placeholders to set these parameters. This will protect you from SQL injection attacks also. Here is an example

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

4 Comments

please can u tell how to use preparestatement
@limelights now i get a run time error . java.lang.UnsupportedOperationException:Notyet implemented
From where? Make a new question and post your code and stacktrace or update this question with the stacktrace, please.

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.