java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]No ResultSet set was produced.

qbstk 2009-03-18 09:36:50
错误如下:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]No ResultSet set was produced.

出错代码如下

public static void delCategory(int id) {
Connection conn = null ;
ResultSet rs = null ;
String sql = null ;
try {
conn = DB.getConn() ;
//删除id = id的节点
sql = "delete from category where id = " + id ;
DB.executeQuery(conn, sql) ;

//删除pid=id的节点和其下所有子节点
//返回该id下的所有子节点
rs = DB.executeQuery(conn, "select * from category where pid = " + id ) ;
while(rs.next()){
//对每个子节点进行递归
int pid = rs.getInt("id") ;
delCategory(pid) ;
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
DB.closeRs(rs) ;
DB.closeConn(conn) ;
}
}

数据库中会更新,因为要用到resultSet,所以只能用executeQuery不能用executeupdate
请高手帮忙啊!
...全文
362 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qbstk 2009-03-20
  • 打赏
  • 举报
回复
谢谢各位
二楼是对的,是我看错了,我以为说的是下面那条语句!
眼睛不知长哪去了!
qbstk 2009-03-19
  • 打赏
  • 举报
回复
//返回结果集的方法
public static ResultSet executeQuery(Connection conn , String sql){
ResultSet rs = null ;
try {
rs = conn.createStatement().executeQuery(sql) ;
} catch (SQLException e) {
e.printStackTrace();
}
return rs ;
}


这是executequery方法!
executeupdate返回int类型的啊,我需要拿到结果集里面的字段,不返回resultSet就拿不到啊!!
请大侠指点指点啊!

DB里面封装的不是很好,还有待改进。现在得先解决上面这个问题,每次调试的时候都跑出来那个错不爽啊!
yiyi_wx 2009-03-19
  • 打赏
  • 举报
回复
请lz弄明白
executeQuery(sql) 用于执行查询语句 会返回所要查询的result集合
executeUpdate(sql)用于执行insert、delete、update语句,返回受影响的情况
参见API:
executeQuery(String sql)
执行给定的 SQL 语句,该语句返回单个 ResultSet 对象。
executeUpdate(String sql)
执行给定 SQL 语句,该语句可能为 INSERT、UPDATE 或 DELETE 语句,或者不返回任何内容的 SQL 语句(如 SQL DDL 语句)。
fosjos 2009-03-19
  • 打赏
  • 举报
回复
楼主有没有弄明白?我说的是这两句
sql = "delete from category where id = " + id ;
DB.executeQuery(conn, sql) ;
你delete返回rs做什么?
fosjos 2009-03-18
  • 打赏
  • 举报
回复
DB.executeQuery(conn, sql) ;这句的问题,为什么不能用executeupdate ?

另外DB.getConn()不是每次都新建连接吧

81,092

社区成员

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

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