我有一个函数,它将查询发送到我的数据库并将结果保存到结果集中。另一个函数应该采用结果集的值并将其放在hashmap中。如果我调试我的代码,获取db数据的函数返回结果集中的值,但如果我将该结果集作为参数提供给hashmap函数,则表示结果集为空。我从昨天起就坐在这个问题上,找不到任何答案。有人可以在我的代码中发现任何错误吗?
这是我的Hashmap函数和用于创建结果集的函数。
public HashMap<String, List<ResultSet>> toHashMap(ResultSet rset) throws SQLException, IOException {
HashMap<String, List<ResultSet>> hmap = new HashMap<String, List<ResultSet>>();
while (rset.next()) {
String Processday = rset.getString("PROCESSDAY");
if (hmap.containsKey(Processday)) {
List<ResultSet> s = hmap.get(Processday);
s.add(rset);
} else {
List<ResultSet> newList = new ArrayList();
newList.add(rset);
hmap.put(Processday, newList);
}
System.out.println(hmap.size());
// convertToKML(distance, ax, ay, sx, sy, out);
}
return hmap;
}
这是我的结果集函数。
public ResultSet getDBData(Connection conn, String[] args, RequiredMethods kml) throws SQLException{
ResultSet rset;
stmt = conn.createStatement();
String sql_query;
String[] userinput = kml.getUserInput(args);
// String sql_query = "SELECT * from STOPPOINT_CORRECTED_BVAGG WHERE
// trunc(PROCESSDAY) BETWEEN to_date('" + dateargs +"','ddmmyy') AND
// to_date('" + toDate +"','ddmmyy') AND actualx is not null and
// actualy is not null and distance is not null";
if(userinput[0].isEmpty()){
sql_query = "select distinct(trunc(PROCESSDAY)) PROCESSDAY,STOPPOINTID,ACTUALX,ACTUALY,SCHEDULEDX,SCHEDULEDY, DISTANCE from tabletest WHERE trunc(PROCESSDAY) = to_date('" + kml.getDateAsString()
+ "','ddmmyy') AND actualx is not null and actualy is not null and distance is not null";
}
else if (userinput[1] == null) {
sql_query = "select distinct(trunc(PROCESSDAY)) PROCESSDAY,STOPPOINTID,ACTUALX,ACTUALY,SCHEDULEDX,SCHEDULEDY, DISTANCE from tabletest WHERE trunc(PROCESSDAY) = to_date('" + userinput[0]
+ "','ddmmyy') AND actualx is not null and actualy is not null and distance is not null";
}else{
sql_query = "select distinct(trunc(PROCESSDAY)) PROCESSDAY,STOPPOINTID,ACTUALX,ACTUALY,SCHEDULEDX,SCHEDULEDY, DISTANCE from tabletest WHERE trunc(PROCESSDAY) BETWEEN to_date('" + userinput[0]
+ "','ddmmyy') AND to_date('" + userinput[1]
+ "','ddmmyy') AND actualx is not null and actualy is not null and distance is not null";
}
System.out.println(sql_query);
rset = stmt.executeQuery(sql_query);
System.out.println("Query sent");
/*while(rset.next()){
System.out.println(rset.getString("ACTUALX"));
}*/
return rset;
}