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をPaymentオブジェクトのリストにコピーします。支払オブジェクトの一覧を返します。あなたのvalidatePaymentsメソッドはあまりにも多くのことをしています。メソッドを多くの小さなメソッドに分割します。 –
現在のコードで何が問題になっていますか? –
私はメソッドシグネチャを呼び出す変更する場合、私は非常に多くの場所で変更を加える必要があるそのレガシーコード。呼び出しメソッドは、結果セットを期待しています。 – user3647134