0

i get an error wherein it says SQL Exception: java.sql.SQLException: No data found, i cant seems to find the problem here. please help me, sorry for asking.

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);

    }
user1694994
  • 55
  • 1
  • 3
  • 4
  • 1
    Does the data you are trying to remove exists?? But actually that too should not throw an exception.. – Rohit Jain Oct 06 '12 at 09:57
  • you are using jdbc-odbc driver, not sure but check this [link](http://stackoverflow.com/questions/9498231/java-sql-sqlexception-no-data-found). Might be helpful. – Nandkumar Tekale Oct 06 '12 at 10:36

2 Answers2

1

I can think about 2 issues

  1. This could be because of unnecessary white spaces that getText() doesn't eliminate. Try txtId.getText().trim()

  2. URL might be wrong.

Apart from that, do the following to improve the code.

  1. Print complete stack trace
  2. Use PreparedStatement instead of statement.
PeakGen
  • 21,894
  • 86
  • 261
  • 463
0
statement.executeUpdate( "DELETE from Employee where EmployeeID ="+txtId.getText()+"" );

try using this

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

note the addition of single inverted comma at the start and end of txtId.getText()

Bhavik Shah
  • 5,125
  • 3
  • 23
  • 40