Привет, Java / база данных рядом, где синтаксическая ошибка - PullRequest
0 голосов
/ 16 ноября 2018

Каждый раз, когда я пытаюсь обновить, он говорит - рядом с "ГДЕ": синтаксическая ошибка. Я успешно смог обновить другие части классов в программе, но это как-то дает мне эту ошибку.

Я думаю, что проблема заключается здесь:

public void update_account(){
           try { //start or try
               //1)create a connection variable
               Connection con;
               //2)create an instance of the database class
               Database db=new Database();
               //3)pass the connection from DB to con
               con=db.open_connection();
               //4)create a statement variable to prepare the SQL
               Statement statement=con.createStatement();
               //5)create a query to insert the records
               String query="UPDATE tblUsers SET fullname='" + txtFullname.getText()+"',"
                    + "username='" + txtUsername.getText()+"',"
                    + "password='" + txtPassword.getText()+"',"
                    + "WHERE userID="+ accid +"";
               //6) execute the SQL code
               if(statement.executeUpdate(query)==1) { //query was successful
                   JOptionPane.showMessageDialog(null, "Reference successfully updated!");
                   //clear the inputs
                   new MainInterface(user);
                   frmAccountSett.dispose();

               }
           }//end of try
           catch (Exception e){//start of catch
               //display the error
               JOptionPane.showMessageDialog(null,e.getMessage());
           }//end of catch
        }//end of save_recipe()

Вот весь код на всякий случай;

public void update_account(){
           try { //start or try
               //1)create a connection variable
               Connection con;
               //2)create an instance of the database class
               Database db=new Database();
               //3)pass the connection from DB to con
               con=db.open_connection();
               //4)create a statement variable to prepare the SQL
               Statement statement=con.createStatement();
               //5)create a query to insert the records
               String query="UPDATE tblUsers SET fullname='" + txtFullname.getText()+"',"
                    + "username='" + txtUsername.getText()+"',"
                    + "password='" + txtPassword.getText()+"',"
                    + "WHERE userID="+ accid +"";
               //6) execute the SQL code
               if(statement.executeUpdate(query)==1) { //query was successful
                   JOptionPane.showMessageDialog(null, "Reference successfully updated!");
                   //clear the inputs
                   new MainInterface(user);
                   frmAccountSett.dispose();

               }
           }//end of try
           catch (Exception e){//start of catch
               //display the error
               JOptionPane.showMessageDialog(null,e.getMessage());
           }//end of catch
        }//end of save_recipe()

1 Ответ

0 голосов
/ 16 ноября 2018

Для обновления таблицы sql синтаксис следующий:

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Обратите внимание, что перед ключевым словом where нет запятой. В своем коде вы добавляете запятую перед ключевым словом WHERE, ведущим к ошибке

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...