国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Operation not allowed after ResultSet closed

2019-11-06 06:19:17
字體:
來源:轉載
供稿:網友

     今天做學校的精品課程網 ,又遇到了一些問題,錯誤提示是:Operation not allowed after ResultSet closed,

在網上找了一下,一篇文章解決了我的問題,如下

一個stmt多個rs進行操作引起的ResultSet已經關閉錯誤

一個stmt多個rs進行操作.那么從stmt得到的rs1,必須馬上操作此rs1后,才能去得到另外的rs2,再對rs2操作.不能互相交替使用,會引起rs已經關閉錯誤.錯誤的代碼如下: stmt=conn.createStatement(); rs=stmt.executeQuery("select * from t1"); rst=stmt.executeQuery("select * from t2"); rs.last();//由于執行了rst=stmt.executeQuery(sql_a);rs就會被關閉掉!所以程序執行到此會提示ResultSet已經關閉.

錯誤信息為:java.sql.SQLException: Operation not allowed after ResultSet closed rst.last();正確的代碼: stmt=conn.createStatement(); rs=stmt.executeQuery("select * from t1"); rs.last();//對rs的操作應馬上操作,操作完后再從數據庫得到rst,再對rst操作 rst=stmt.executeQuery("select * from t2"); rst.last();原因是: The  object  used  for  executing  a  static  SQL  statement  and  returning  the  results  it  PRoduces.     By  default,  only  one  ResultSet  object  per  Statement  object  can  be  open  at  the  same  time.

  Therefore,  if  the  reading  of  one  ResultSet  object  is  interleaved  with  the  reading  of  another,  

each  must  have  been  generated  by  different  Statement  objects.  

All  execution  methods  in  the  Statement  interface  implicitly  close  a  statment's  current  ResultSet  object 

 if  an  open  one  exists.     一個stmt最好對應一個rs, 如果用一個時間內用一個stmt打開兩個rs同時操作,會出現這種情況.所以解決此類問題:1.就多創建幾個stmt,一個stmt對應一個rs;2.若用一個stmt對應多個rs的話,

那只能得到一個rs后就操作,處理完第一個rs后再處理其他的,如上"正確代碼".多個stmt對應各自的rs.stmt=conn.createStatement();stmt2=conn.createStatement();rs=stmt.executeQuery("select * from t1");rst=stmt2.executeQuery("select * from t2");rs.last();rst.last();

--本篇文章轉自:http://blog.csdn.net/sku0923/article/details/1722370


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宝坻区| 三穗县| 韩城市| 类乌齐县| 平果县| 沅江市| 张家口市| 齐齐哈尔市| 辛集市| 星子县| 天峻县| 黑龙江省| 绍兴市| 玉溪市| 玛多县| 页游| 洛扎县| 西丰县| 石景山区| 秦皇岛市| 威信县| 平原县| 凤山市| 布拖县| 肥西县| 大埔县| 五峰| 天台县| 柳江县| 河津市| 如东县| 广丰县| 巴青县| 都江堰市| 克拉玛依市| 福建省| 玛曲县| 尚志市| 吴川市| 洛川县| 定襄县|