0

我在 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);
}
4

2 回答 2

1

你不需要PreparedStatement。而是使用这个:

Statement stmt = database.getConnection().createStatement();
于 2013-04-19T07:25:00.570 回答
0

听起来很奇怪,但正如预期的那样,你可以尝试使用

getInt(1)

代替

getString(1)
于 2013-04-19T07:23:15.920 回答