我在sqlite查询结果中的子查询中遇到问题。执行以下查询时,在Sqlite数据库中成功返回结果,但是在运行程序时,它不返回任何值。我在以下程序中做错了什么。请指教。
查询:
select * from (SELECT count(*), col2,col9,col4 FROM tbl_data_1 WHERE col4=6 AND col3 BETWEEN '2012-11-21' AND '2013-04-19' GROUP BY col2,col9,col4) as inr_qry where col2= '20016' and col9='3'
Java程序:
Vector<Vector> dataList = new Vector();
for (int i =0; i < listRows.size(); i++){
Vector cols = new Vector();
cols.add(listRows.get(i));
for (int j = 1; j < listColumns.size(); j++){
// below query will be dynamic
String inner_query = "select * from (SELECT count(*), col2,col9,col4 FROM tbl_data_1 WHERE col4=6 AND col3 BETWEEN '2012-11-21' AND '2013-04-19' GROUP BY col2,col9,col4) as inr_qry where col2= '20016' and col9='3'";
PreparedStatement data_st = database.getConnection().prepareStatement(inner_query);
ResultSet data_rs = data_st.executeQuery();
while (data_rs.next()) { // result not successful, result set not having records
SLogger.printD("data_rs.getString(1): " +data_rs.getString(1));
cols.add(data_rs.getString(1));
}
}
dataList.add(cols);
}
最佳答案
您不需要PreparedStatement
。而是使用此: