gpt4 book ai didi

java - 如何在使用 ResulSet.absolute() 方法时从 java 中的 LinkedHashMap 检索所有值

转载 作者:行者123 更新时间:2023-12-01 11:58:05 25 4
gpt4 key购买 nike

我必须从 ResultSet 中仅检索一些特定的行,因为我有 ResultSet 的absolute() 方法,并将该行的值放入 LinkedHashMap 中。但是当我执行代码时,仅打印最后一行,而不是所有指定的行。代码是:

public LinkedHashMap <Date, Double> reference() {
int rowCounter = 0;


String a[][] = new String[46][2];
int i = 0;
try {
con = getConnection();
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
String sql = "select logtime,beam_current from INDUS2_BDS.dbo.DCCT where logtime between '2014-10-10 07:17:00' and '2014-10-10 08:46:00'" +
"and (beam_current like '%9.96' or beam_current like '%9.97' or beam_current like '%9.98' or beam_current like '%9.99' or beam_current like '%0' or beam_current like '%_0.01' or beam_current like '%_0.02' or beam_current like '%_0.03' or beam_current like '%_0.04' or beam_current like '%_0.05' or beam_current like '%_0.06')";
stmt.executeQuery(sql);
rs = stmt.getResultSet();



while (rs.next()) {

for (int j = 0; j < 2; j++)

{

a[i][j] = rs.getString(j + 1);
}

i++;
rowCounter++;

System.out.println(rowCounter);
if (rowCounter == 4 || rowCounter == 9 || rowCounter == 11 || rowCounter == 13 || rowCounter == 15)
rs.absolute(4);
map.put(rs.getDate(1), (double) rs.getFloat(2));
rs.absolute(9);
map.put(rs.getDate(1), rs.getDouble(2));
rs.absolute(11);
map.put(rs.getDate(1), rs.getDouble(2));
rs.absolute(13);
map.put(rs.getDate(1), rs.getDouble(2));
rs.absolute(15);
map.put(rs.getDate(1), rs.getDouble(2));
rs.absolute(16);
map.put(rs.getDate(1), rs.getDouble(2));
rs.absolute(18);
map.put(rs.getDate(1), rs.getDouble(2));

}
}


} catch (Exception e) {
System.out.println("\nException " + e);
} finally {
closeConnection(stmt, rs, con);
}

return map;

我希望检索结果集的absolute()方法中指定的所有行。如何做到这一点?

最佳答案

使用列表集合将 map 键/值对添加为

List<LinkedHashMap<String,String>>l=new ArrayList<LinkedHashMap<String,String>>();  
l.add(map);

然后返回列表变量l。

关于java - 如何在使用 ResulSet.absolute() 方法时从 java 中的 LinkedHashMap 检索所有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28274445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com