我想編寫一個查詢,該查詢應該從java中的數據庫打印xml標記的值。嵌套執行查詢「結果集關閉」錯誤
<employee emp:empid=" " emp:empname="" /><location loc:locname=" "/>
下面的代碼給出了錯誤
「的結果集被關閉」。
這怎麼解決?
connection = dataSource.getConnection();
ResultSet rs;
connection.setAutoCommit(false);
System.out.println("Connected to server OELDBSQL!!!");
Statement stmt = connection.createStatement();
String querystring = "select empid,empname from empt";
rs = stmt.executeQuery(querystring);
Element child1 = doc.createElement("employee");
try {
while (rs.next()) {
child1.setAttributeNS(emp, "emp:empid", rs.getString(1));
child1.setAttributeNS(emp, "emp:empname", rs.getString(2));
}
String querystring1 = "select locname from Locate";
ResultSet rs1;
rs1 = stmt.executeQuery(querystring1);
while (rs1.next()) {
Element element = doc.createElement("location");
child1.appendChild(element);
element.setAttributeNS(loc, "loc:locaname", rs.getString(1));
}
} catch (Exception e) {
System.out.println("Exception in connecting to DB"
+ e.getMessage());
System.err.println(e.getMessage());
}
} catch (Exception e) {
System.out
.println("Exception in connecting to DB" + e.getMessage());
System.err.println(e.getMessage());
}
我嘗試沒有嘗試塊使用單循環結果集。 – Sharada
querystring =「從empt中選擇empt.empid,empt.empname,locate.locname,找到;然後給出多個值表示假設empt表有5個名字,這5個名字用locname重複5次。行 – Sharada