亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

缺少數據庫(靠近“where”:語法錯誤)

缺少數據庫(靠近“where”:語法錯誤)

Helenr 2021-11-24 19:00:31
我正在嘗試更新我的 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);
查看完整描述

1 回答

?
蠱毒傳說

TA貢獻1895條經驗 獲得超3個贊

錯誤是您在沒有字段的情況下添加了姓氏值:

... +"','"+ lname.getText() +"' ...

您錯過了值之前的姓氏參數,例如:

... +"', lastname='"+ lname.getText() +"' ...

成為

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


查看完整回答
反對 回復 2021-11-24
  • 1 回答
  • 0 關注
  • 295 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號