oracle - java.sql.SQLException : ORA-01002: fetch out of sequence on XATransaction

标签 oracle jdbc transactions glassfish

在相同的数据上有时会抛出异常 java.sql.SQLException: ORA-01002: fetch out of sequence,但在大多数尝试中都可以正常工作。

在 Glassfish 3.1.2.2 上运行的 Java 应用程序。谁能解释一下,问题出在哪里?

@Singleton
@LocalBean
@Startup
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class MarketCodesSingleton {

    @Resource(mappedName="jdbc/sss")
    private DataSource source;

    private volatile static Map<Interval, String> marketCodes;

    @PostConstruct
    @Schedule(minute="*/10", hour="*")
    public void fillMarketCodes() {
        try(Connection conn = source.getConnection()) {
            Map<Interval, String> marketCodesInt = new TreeMap<>();
            DaoFactory.getMarketCodesDao().fillMarketCodes(marketCodesInt, conn);
            marketCodes = Collections.unmodifiableMap(marketCodesInt);
            Logger.getLogger(getClass().getName()).log(Level.FINE, "MarketCodes updated");
        } catch (SQLException e) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "fillMarketCodes exception",e);
            throw new EJBException("fillMarketCodes exception",e);
        }
    }

    public String getMarketCode(Long msisdn) {
        Interval interval = new Interval(msisdn);
        return marketCodes.get(interval);
    }

}

DaoFactory.getMarketCodesDao().fillMarketCodes:
private static final String getMarketCodes_SQL = "CALL SERVICE_PKG.GET_MARKET_CODES(?)";

@Override
public void fillMarketCodes(Map<Interval, String> intervals, Connection conn) throws SQLException {      
    try (CallableStatement cs = conn.prepareCall(getMarketCodes_SQL)) {
        //-10 is a OracleTypes.CURSOR
        cs.registerOutParameter(1, -10);
        cs.execute();
        try (ResultSet rs = (ResultSet) cs.getObject(1)) {
            //*******Exception throws on the rs.next() in this method*******
            while (rs.next()) {
                Interval interval = new Interval(rs.getLong("from_no"), rs.getLong("to_no"));
                intervals.put(interval, rs.getString("market_code"));
            }
        }
    }
}

程序:
  procedure GET_MARKET_CODES(
    c_cursor OUT SYS_REFCURSOR
  ) AS
  BEGIN
    OPEN c_cursor FOR
      SELECT from_no, to_no, market_code
      FROM market_codes;
  END GET_MARKET_CODES;

连接属性:
<jdbc-connection-pool 
    connection-creation-retry-interval-in-seconds="5" 
    datasource-classname="oracle.jdbc.xa.client.OracleXADataSource" 
    max-pool-size="200" 
    max-connection-usage-count="1000" 
    res-type="javax.sql.XADataSource" 
    steady-pool-size="0" 
    name="sss_pool" 
    connection-creation-retry-attempts="5">
      <property name="URL" value="jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = xx)))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = xx)))"></property>
      <property name="Password" value="***"></property>
      <property name="User" value="***"></property>
</jdbc-connection-pool>

最佳答案

代码不完整,只能猜测:

  • 游标已关闭,您尝试再次获取
  • 您确实选择了更新并提交,然后尝试获取下一行。
  • 关于oracle - java.sql.SQLException : ORA-01002: fetch out of sequence on XATransaction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20264735/

    相关文章:

    oracle - 如何从 Oracle 10 模式导出 ddl 脚本以在 H2 数据库中创建表和约束?

    java - 使用 DBunit 导出数据库时出错 "java.lang.NoClassDefFoundError: org/dbunit/database/IDatabaseConnection"

    jdbc - 在 Spark 中,CREATE TABLE 命令是否创建外部表?

    java - 我有一个使用 Netbeans 的 swing 应用程序。我正在尝试将用户对象插入到数据库表中。但我收到以下错误

    java - Spring TransactionSynchronizationManager isActualTransactionActive() 和 getCurrentTransactionName() 混淆

    oracle - 具有引用分区的直接路径插入?

    oracle - Oracle 调度链如何包含使用参数调用程序的步骤

    sql - Oracle中如何选择一个变量的值?

    transactions - Redis 中的顺序监视调用

    c# - 使用 C# 在 Mysql 中使用回滚