2012-10-06 128 views
0

我得到一個錯誤,其中說,SQL異常:java.sql.SQLException:沒有找到數據,我似乎無法找到這裏的問題。請幫助我,抱歉問。SQL異常:java.sql.SQLException:沒有找到數據

try{ 
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
    String url = "jdbc:odbc:ict11"; 
    Connection con = DriverManager.getConnection(url); 
    Statement statement = con.createStatement(); 
     statement.executeUpdate("DELETE from Employee where EmployeeID ="+txtId.getText()+""); 
     statement.close(); 
    con.close(); 
    JOptionPane.showMessageDialog(rootPane, "Successfully Deleted"); 
    } 
     catch(Exception e){ 
     JOptionPane.showMessageDialog(null, e); 

    } 
+1

請問您要刪除的數據存在的開始和結束?但實際上,也不應該拋出異常。 –

+0

您正在使用哪種DBMS? – Vikdor

+0

您正在使用jdbc-odbc驅動程序,不確定但請檢查此[鏈接](http://stackoverflow.com/questions/9498231/java-sql-sqlexception-no-data-found)。可能有幫助。 –

回答

1

我能想到的2個問題

  1. 這可能是因爲不必要的空白空間,gettext的()並沒有消除的。試試txtId.getText().trim()

  2. URL可能是錯誤的。

除此之外,請執行以下操作來改進代碼。

  1. 打印完整的堆棧跟蹤
  2. 利用PreparedStatement而不是語句。
0
statement.executeUpdate("DELETE from Employee where EmployeeID ="+txtId.getText()+""); 

嘗試使用此

statement.executeUpdate("DELETE from Employee where EmployeeID ='"+txtId.getText()+"'"); 

注意到另外一個倒逗號在txtId.getText()

相關問題