`
weilJava
  • 浏览: 70032 次
  • 性别: Icon_minigender_1
  • 来自: 南京
文章分类
社区版块
存档分类
最新评论

Fail to convert to internal representation

 
阅读更多

 今天遇到了这个异常

java.sql.SQLException: Fail to convert to internal representation
	at oracle.jdbc.driver.CharCommonAccessor.getLong(CharCommonAccessor.java:297)
	at oracle.jdbc.driver.T4CVarcharAccessor.getLong(T4CVarcharAccessor.java:849)
	at oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:939)
	at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:440)
	at com.alibaba.druid.pool.DruidPooledResultSet.getLong(DruidPooledResultSet.java:304)
	at cn.egame.data.core.rowmapper.js.OpenChannelSettlementsRowMapper.mapRow(OpenChannelSettlementsRowMapper.java:21)
	at cn.egame.data.core.rowmapper.js.OpenChannelSettlementsRowMapper.mapRow(OpenChannelSettlementsRowMapper.java:14)

 

java代码

        bean.setDistributorId(rs.getLong("distributor_id"));

 这里数据库中distributor_id为varchar2,用getLong去出来

 

此问题非必现,查看数据也没问题

 

来查看下各个类的源码(反编译的,此包非开源)

OracleResultSetImpl

public synchronized long getLong(int var1) throws SQLException {
        if(var1 <= 0 || var1 > this.statement.numberOfDefinePositions) {
            DatabaseError.throwSqlException(3);
        }

        if(this.closed) {
            DatabaseError.throwSqlException(11);
        }

        int var2 = this.statement.currentRow;
        if(var2 < 0) {
            DatabaseError.throwSqlException(14);
        }

        this.statement.lastIndex = var1;
        if(this.statement.streamList != null) {
            this.statement.closeUsedStreams(var1);
        }
        //T4CVarcharAccessor.getLong
        return this.statement.accessors[var1 - 1].getLong(var2);
    }

 

几个类的关系如下

T4CVarcharAccessor extends VarcharAccessor extends CharCommonAccessor

 

如下是CharCommonAccessor.getLong方法

 

long getLong(int var1) throws SQLException {
        long var2 = 0L;
        if(this.rowSpaceIndicator == null) {
            DatabaseError.throwSqlException(21);
        }

        if(this.rowSpaceIndicator[this.indicatorIndex + var1] != -1) {
            try {
                var2 = Long.parseLong(this.getString(var1).trim());
            } catch (NumberFormatException var5) {
                DatabaseError.throwSqlException(59);
            }
        }

        return var2;
    }

 

 

反编译代码如下

/*     */   long getLong(int paramInt)
/*     */     throws SQLException
/*     */   {
/* 273 */     long l = 0L;
/*     */ 
/* 275 */     if (this.rowSpaceIndicator == null)
/*     */     {
/* 279 */       SQLException localSQLException1 = DatabaseError.createSqlException(getConnectionDuringExceptionHandling(), 21);
/* 280 */       localSQLException1.fillInStackTrace();
/* 281 */       throw localSQLException1;
/*     */     }
/*     */ 
/* 287 */     if (this.rowSpaceIndicator[(this.indicatorIndex + paramInt)] != -1)
/*     */     {
/*     */       try
/*     */       {
/* 291 */         l = Long.parseLong(getString(paramInt).trim());
/*     */       }
/*     */       catch (NumberFormatException localNumberFormatException)
/*     */       {
/* 296 */         SQLException localSQLException2 = DatabaseError.createSqlException(getConnectionDuringExceptionHandling(), 59);
/* 297 */         localSQLException2.fillInStackTrace();
/* 298 */         throw localSQLException2;
/*     */       }
/*     */ 
/*     */     }

 报错在297行,也就是

“java.sql.SQLException: Fail to convert to internal representation”

 

从291行看,网上搜到很多方法说将getLong变为getString,在数据为数字的情况下,个人觉得没有实际意义

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics