ResultSet.previous无法正常工作

时间:2014-04-16 09:56:33

标签: java jdbc

似乎我无法按照我想要的方式滚动ResultSet

public void getCurves(String runId, File file, Connection conn) {
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        ps = conn.prepareStatement(CDS, ResultSet.TYPE_SCROLL_INSENSITIVE);
        int k = ps.getResultSetType();
        ps.setString(1, runId);
        ps.setFetchSize(1500);
        rs = ps.executeQuery();

        ccw.writeCore(file, rs);
        ccw.writeFooter(file, "value;data");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        close(rs, ps);
    }
}

在这里,即使我将ResultSet.type设置为ResultSet.TYPE_SCROLL_INSENSITIVE,这是一个值为1004的常量,k值为1003,相当于ResultSet.TYPE_FORWARD_ONLY

我错误地设置了这个吗?

编辑:我使用的是oracle.jdbc.driver.OracleDriver

1 个答案:

答案 0 :(得分:4)

您没有设置ResultSet类型,因此您将其保留为默认值,即:ResultSet.TYPE_FORWARD_ONLY。以下是您的方法API:http://docs.oracle.com/javase/6/docs/api/java/sql/Connection.html#prepareStatement(java.lang.String,int)

您必须使用:

prepareStatement(sql, resultSetType, resultSetConcurrency);

OR

prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);

所以对你来说,这应该足够了:

conn.prepareStatement(CDS, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);