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

    }
2
  • 1
    Does the data you are trying to remove exists?? But actually that too should not throw an exception.. Commented Oct 6, 2012 at 9:57
  • you are using jdbc-odbc driver, not sure but check this link. Might be helpful. Commented Oct 6, 2012 at 10:36

2 Answers 2

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.
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.