猿问

缺少数据库(靠近“where”:语法错误)

我正在尝试更新我的 sqlite3 数据库,但它给出了这个错误。我能够成功地将数据插入同一个数据库,但我无法更新它。请帮忙。


[SQLITE_ERROR] SQL error or missing database (near "where": syntax error)

at org.sqlite.core.DB.newSQLException(DB.java:909)

at org.sqlite.core.DB.newSQLException(DB.java:921)

at org.sqlite.core.DB.throwex(DB.java:886)

at org.sqlite.core.NativeDB.prepare_utf8(Native Method)

at org.sqlite.core.NativeDB.prepare(NativeDB.java:127)

at org.sqlite.core.DB.prepare(DB.java:227)

at org.sqlite.core.CorePreparedStatement.<init>(CorePreparedStatement.java:45)

at org.sqlite.jdbc3.JDBC3PreparedStatement.<init>(JDBC3PreparedStatement.java:30)

at org.sqlite.jdbc4.JDBC4PreparedStatement.<init>

我的代码


btnUpdate = new JButton("Update");

    btnUpdate.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {

            try {

                String query = "update students set ID='"+ id.getText() +"' , username='"+ username.getText() + "', password='"+ pass.getText() +"', firstname='"+ fname.getText() +"','"+ lname.getText() +"' WHERE ID='"+ id.getText() +"'  ";

                PreparedStatement pst = connection.prepareStatement(query);

                pst.execute();


                JOptionPane.showMessageDialog(null,"data updated successfully");


                pst.close();


            } catch (Exception e) {

                e.printStackTrace();

            }

        }

    });

    btnUpdate.setFont(new Font("Tahoma", Font.PLAIN, 20));

    btnUpdate.setBounds(199, 246, 126, 43);

    contentPane.add(btnUpdate);


Helenr
浏览 269回答 1
1回答

蛊毒传说

错误是您在没有字段的情况下添加了姓氏值:...&nbsp;+"','"+&nbsp;lname.getText()&nbsp;+"'&nbsp;...您错过了值之前的姓氏参数,例如:...&nbsp;+"',&nbsp;lastname='"+&nbsp;lname.getText()&nbsp;+"'&nbsp;...成为String&nbsp;query&nbsp;=&nbsp;"update&nbsp;students&nbsp;set&nbsp;ID='"+&nbsp;id.getText()&nbsp;+"'&nbsp;,&nbsp;username='"+&nbsp;username.getText()&nbsp;+&nbsp;"',&nbsp;password='"+&nbsp;pass.getText()&nbsp;+"',&nbsp;firstname='"+&nbsp;fname.getText()&nbsp;+"',&nbsp;lastname='"+&nbsp;lname.getText()&nbsp;+"'&nbsp;WHERE&nbsp;ID='"+&nbsp;id.getText()&nbsp;+"'&nbsp;&nbsp;";
随时随地看视频慕课网APP

相关分类

Java
我要回答