public ResultSet validatePayments() {
ConnectionPool connPool = null;
Connection dbConn = null;
Connection dbUpdatConn = null;
CallableStatement callableStatement = null;
PreparedStatement psmt = null;
ResultSet rs = null;
CachedRowSetImpl crs = null;
Statement stmt = null;
List<UpdatePaymentResult> upr = new ArrayList<UpdatePaymentResult>();
String sqlStatement = "{call myschema.mypkg.sp_get_new_payments(?)}";
String updateSql = "UPDATE temp SET stats= ? ,THREAD = ? WHERE P_NUM = ? ";
try {
Logger.log(Logger.DEBUG, "SQL=" + sqlStatement,
"Creating Connection ....");
connPool = ConnectionPool.getConnectionPool();
dbConn = connPool.getConnection();
callableStatement = dbConn.prepareCall(sqlStatement,
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
callableStatement.registerOutParameter(1, OracleTypes.CURSOR);
callableStatement.executeQuery();
rs = (ResultSet) callableStatement.getObject(1);
crs = new CachedRowSetImpl();
crs.populate(rs);
dbUpdatConn = connPool.getConnection();
psmt = dbUpdatConn.prepareStatement(updateSql);
Logger.log(Logger.DEBUG, "SQL=" + "",
"prepared statement started.... ");
while (rs.next()) {
Logger.log(Logger.DEBUG, "SQL=" + "",
"inside loop started.... ");
UpdatePaymentResult up = new UpdatePaymentResult();
up.setPaymentReqNum(rs.getString("P_NUM"));
upr.add(up);
for (UpdatePaymentResult updatePaymentResult : upr) {
psmt.setString(1, processing);
psmt.setString(2, "my payment thread");
psmt.setString(3, updatePaymentResult.getPaymentReqNum());
psmt.executeUpdate();
}
}
Logger.log(Logger.DEBUG, "SQL=" + "",
"prepared statement started.... ");
} catch (Exception e) {
Logger.log(Logger.RECEIVER, "Error while getting Payment record "
+ e, "selectNew :");
} finally {
try {
if (rs != null)
rs.close();
if (callableStatement != null)
callableStatement.close();
if (psmt != null)
psmt.close();
if (connPool != null && dbConn != null) {
dbConn.setAutoCommit(true);
connPool.returnConnection(dbConn);
}
} catch (SQLException e) {
Logger.log(Logger.Debug,
"Error whilst getting Payment record" + e, "hello");
}
}
return crs;
}
大家好,如何選擇和更新結果集?
我想選擇DB值的列表,將結果傳遞到其他類。同時,我想收取付款編號並將狀態更新爲「處理」。一旦我將結果集傳遞給另一個方法,它會將狀態更新爲「已處理」。我在循環中保留了一些記錄器,我們也有審計表。我無法看到處理狀態。你能否請一個人幫我解決我犯的錯誤。
ResultSet並不意味着保持打開並傳遞。將ResultSet複製到支付對象列表中。返回支付對象列表。你的validatePayments方法做了太多事情。把你的方法分解成許多更小的方法。 –
你目前的代碼有什麼問題? –
它的遺留代碼如果我改變調用方法簽名,我需要在如此多的地方做出如此改變。調用方法期望結果集。 – user3647134