[問題] Java的ResultSet is closed
請教一下,我的Java程式需要存取三次SQLite資料庫的資料
因此分別在不同地方宣告ResultSet的物件,並執行Query
這三個物件使用同一個Statement
而我在存取完資料後,隨即將該Resulteset物件Close掉
想請問一下這樣子的寫法有錯嗎?
因為在第一次執行程式可以正常執行,程式會在我還沒寫完的程式碼exception中止
而當我將資料庫的檔案刪掉,並再次執行程式時
程式執行到第一個Query時,會出現ResultSet is closed錯誤
以下附上我大致上的程式碼供參考,謝謝
==================================
try {
Statement stat_BlogPostDB = conn_BlogPostDB....;
String str_SqlQuery = "Select...";
ResultSet rs_blogSN = stat_BlogPostDB.executeQuery(str_SqlQuery);
if(!(rs_blogSN.next())) {
//存入資料到TABLE-Blogs
}
int_BlogSN = rs_blogSN.getInt("blogSN");
rs_blogSN.close();
for (...) {
if(...) {
for (...) {
str_SqlQuery = "Select...";
ResultSet rs_postSN = stat_BlogPostDB.executeQuery(str_SqlQuery);
if(!(rs_postSN.next())) {
//存入資料到TABLE-Posts
}
rs_postSN.close();
}
}
}
if(...) {
str_SqlQuery = "Select...";
ResultSet rs_postURL = stat_BlogPostDB.executeQuery(str_SqlQuery);
while(rs_postURL.next()) {
//從TABLE-Posts讀取資料
}
}
rs_postURL.close();
//程式未完成,此行後的程式碼將遇到exception中斷
}
conn_BlogPostDB.close();
} catch (Exception e) {
System.out.println(e);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.124.144.102
→
03/17 22:47, , 1F
03/17 22:47, 1F
→
03/19 01:46, , 2F
03/19 01:46, 2F
→
03/29 20:56, , 3F
03/29 20:56, 3F
→
03/29 20:57, , 4F
03/29 20:57, 4F
Programming 近期熱門文章
PTT數位生活區 即時熱門文章