0

我需要关于 Java ejb Web 服务的传入请求计数器的建议。部署 Web 服务的应用服务器有 4 个节点,因此传入的请求可以在 4 个节点中的任何一个上处理,我决定将计数器值存储在 Oracle 数据库中。我通过调用设置了当前的请求数,select SEQPACKSCYCLETOT.NEXTVAL from dual它工作正常。

但是我还需要显示当前的计数器值,这是一个问题。当我打电话时,select SEQPACKSCYCLETOT.CURRVAL from dual有时会出现异常sequence SEQPACKSCYCLETOT.CURRVAL is not yet defined in this session

它是关于什么会话以及如何使用它?这是代码片段:

@Singleton
public class DbWorkerImpl implements DbWorker {
@Override
public Long getPacksTotSeqValue() throws SQLException {
    String query = "select SEQPACKSCYCLETOT.CURRVAL from dual";
    Long packetsCount = null;
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        conn = ds.getConnection(Username, Password);
        stmt = conn.createStatement();
        rs = stmt.executeQuery(query);
        if (rs.next())
            packetsCount = rs.getLong(1);
    } 
    catch (SQLException e) {
        logS.debug(this.servername + e.getMessage());
    }
    finally{
        if (rs!=null) rs.close();
        if (stmt!=null) stmt.close();
        if (conn!=null) conn.close();
    }
    return packetsCount;
}
4

0 回答 0