Take the 2-minute tour ×

My concept is that I have to select an item in first combobox. It will add up some items to the second combo box, based on the selection. Once, the second combobox is selected, then some access table data is retrieved.

Finally, when I click Delete, the record has to get deleted based on the item present in the two combo box.

I get the record correctly deleted. But, my problem is, I'm getting an error dialog(which I used in catch) everytime with a

No resultset produced

error in the command prompt, though the deletion happens correctly. I want to know, what's going on inside. Kindly help me diagnose.


  Connection conn=DriverManager.getConnection("jdbc:odbc:vasantham","","");
  Statement st=conn.createStatement();
  ResultSet rs=st.executeQuery("delete from try where tname='"+scb+"' and   Purpose='"+scp+"'");

  JOptionPane.showMessageDialog(null,"Your entry has been DELETED successfully!!!");

catch(Exception e)
  JOptionPane.showMessageDialog(null,"Error!Try again!");

share|improve this question
Can you try to limit the amount of code to the smallest possible program that shows your problem? –  Keppil Jul 20 '12 at 12:30
you should use executeUpdate –  oers Jul 20 '12 at 12:31
@oers: you should make that an answer. –  JB Nizet Jul 20 '12 at 12:34
Empty catch blocks (in the initial code sample) and SQL injections, I really would fix these as well. –  fvu Jul 20 '12 at 12:36
OP, if your exception handling was properly written, your code probably wouldn't even reach SO. You are swallowing all your exceptions except this one, and here you are not saving the stacktrace, which is the key information. System.out.println(e) just gives you the exception name and message. –  Marko Topolnik Jul 20 '12 at 12:36
show 1 more comment

1 Answer

up vote 4 down vote accepted

You are using st.executeQuery which has to be used with selects, as only selects create a ResultSet. You are using an UPDATE query, which will not produce a ResultSet hence the error.

In your case you need to use executeUpdate

int result = st.executeUpdate(...)

The result will contain the number of your deleted (updated) rows.

share|improve this answer
Thank you so much. It worked! So, do you mean that, other than Select, every query must be executed with executeUpdate? –  Gomathi Jul 20 '12 at 12:42
Let me say it this ways: If the statement returns a ResultSet you have to use execute Query (yeah thats probably only SELECT). If no ResultSet can be returned you have to use executeUpdate(INSERT, DELETE, UPDATE). –  oers Jul 20 '12 at 12:44
Thank you. Then where to use PreparedStatement? I read thro' many tutorials, but still couldn't get the key point. What's its purpose?Sorry, I'm a beginner! –  Gomathi Jul 20 '12 at 12:46
Sorry, still I couldn't get the point! Is it same as using executeupdate? If both are same, then why do we need it anyways? –  Gomathi Jul 20 '12 at 12:54
show 2 more comments

Your Answer


