0

I want to update my data and delete it and replace it to another table for a single time. I don't know how to do this.

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version right syntax to use near'(Cash,Change)values('9000','Your Change is:40.0')where Room='9' and Name' at line 1

 try{
    chge=jTextField27.getText();
    cash=jTextField4.getText();

    String SQLL = "update customer (Cash,Chnge) values ('" + cash + "','" + chge + "') where Room = ? and Name = ?;";     
    Dbase5 = conn.prepareStatement (SQLL); 
    Dbase5.setString(1,jTextField1.getText());
    Dbase5.setString(2,jTextField2.getText());
    int b = Dbase5.executeUpdate();

    ////////MOVE TO HISTORY   
    String SQL = "INSERT INTO history select * from customer where Room = ? and Name = ?";     
        Dbase = conn.prepareStatement (SQL);
        Dbase.setString(1,jTextField1.getText());
        Dbase.setString(2,jTextField2.getText());
        int rs=Dbase.executeUpdate();

       ///////MOVE TO HISTORY
    String MSQL = "delete from customer where Room=? and Name=?";
        Dbase1 = conn.prepareStatement (MSQL); 
        Dbase1.setString(1,jTextField1.getText());
        Dbase1.setString(2,jTextField2.getText());
        boolean s = Dbase1.execute();
        this.dispose();
3
  • Edit your question and post the full error. Commented Nov 2, 2016 at 17:59
  • @ROMANIA i edit already, help me Commented Nov 2, 2016 at 18:04
  • Is that UPDATE statement really valid? Shouldn't it be something like update customer set Cash = '123', Chnge = 'foo' where Room = '42' and Name = 'John'? Commented Nov 2, 2016 at 19:06

1 Answer 1

0

All of the above queries are right except the update query:

    update customer (Cash,Chnge) values ('" + cash + "','" + chge + "') where Room = ? and Name = ?;

It should be like below:

    update customer set Cash = '" + cash + "', Chnge = '" + chge + "' where Room = ? and Name = ?;

or you may even set the first two arguments as well with preparedStatement:

    update customer set Cash = ?, Chnge = ? where Room = ? and Name = ?;

I would recommend you to go through the below link: http://dev.mysql.com/doc/refman/5.7/en/update.html

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

Comments

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.