我想将ResultSet
值传输到 HashMap 然后添加它们,所以我最初做了这个代码:
PreparedStatement pstmt=null;
ResultSet rs = null;
String query="SELECT record_id, SUM(ROUND(amtsourcedr, 2)) AS debit, SUM(ROUND(amtsourcecr, 2)) AS credit " +
"FROM adempiere.fact_acct " +
"GROUP BY record_id " +
"ORDER BY record_id ASC";
try
{
pstmt = DB.prepareStatement(query, null);
rs = pstmt.executeQuery();
while (rs.next())
{
int id = rs.getInt("record_id");
BigDecimal sourceDr = rs.getBigDecimal("debit");
BigDecimal sourceCr = rs.getBigDecimal("credit");
System.out.println(id);
System.out.println(sourceDr);
System.out.println(sourceCr);
MCUS_Exam exam = new MCUS_Exam(getCtx(), 0, null);
exam.setCUS_Record_ID(id);
exam.setCUS_AmtSourceDr(sourceDr);
exam.setCUS_AmtSourceCr(sourceCr);
exam.save();
}
是否可以使用hashmap通过java进行查询中的加法和舍入?如果是,那我该怎么做呢?
编辑: GROUP BY 实际上是我在 java 中复制时遇到的困难。
下面是原表:
record_id amountdr amountcr
1000000 0 213.7544
1000000 0 270.00
1000000 483.7544 0
1000001 0 2250.6677
1000001 0 400.5050
1000001 0 12867.75
1000001 15518.9327 0
1000002 0 27000.6543
1000002 27000.6543 0
执行我给出的代码会将其添加到另一个表中:
record_id amountdr amountcr
1000000 483.75 483.75
1000001 15518.92 15518.93
1000002 27000.65 27000.65