线程中断的问题

xywl 2007-06-13 01:26:11
想在execute sql时可以中断
------------------------------------
Thread th=new Thread(){
public void run(){
wait.getLb_Text().setText("Exquting,Please Wait!!!");
wait.setVisible(true);
wait.repaint();
try{
stmt=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE ,java.sql.ResultSet.CONCUR_READ_ONLY );
rs=stmt.executeQuery(sql);
...............................
wait.setVisible(false);
wait.repaint();
}

catch(InterruptedException ex){
System.out.println("System interrupted");
}

}
};
wait.thread=th;
th.start();
-------------------------------------------------------------------

在相应的 try 语句主体中不能抛出异常 java.lang.InterruptedException
catch(InterruptedException ex){
1 错误
...全文
162 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
weihthchk 2007-06-13
  • 打赏
  • 举报
回复
你的try块中没有可抛出InterruptedException的调用,所以不能编译。
你可以尝试一下,用别的线程调用这个Statement的close()方法,然后这里捕获SQLException(必须检查错误代码以区别于执行错误)后即可认定是进行了取消操作。
没有实践过,尝试,尝试一下。
likgui 2007-06-13
  • 打赏
  • 举报
回复
关注

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧