java中的删除操作,在Java中,删除操作是正确的,但catch也会被执行

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.

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

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

System.out.println(e);

}

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值