使用JFinal + Druid连接池支持开发接口应用抛apache.commons.lang.NumberUtil没找到异常反馈

我同事使用JFinal开发接口,用的数据是sql server
 编写代码如下:

 public List<Record> tdPct( String sd, String ed) {
        List<Record> res = null;

        StringBuilder sql = new StringBuilder();

        sql.append("select cast(sum(case when HSNB in('成药费','西药费', '中药费','疫苗费') " +
                "then ORD_TOT_PRC else null end) / sum(ORD_TOT_PRC) * 100.0 as decimal(18,2)) as ypbl, "); // --药品比例;

        sql.append(" cast(sum(case when HSNB in('检查费','诊查费') " +
                "then ORD_TOT_PRC else null end) / sum(ORD_TOT_PRC) * 100.0 as decimal(18,2)) as jcbl, ");//--检查比例

        sql.append(" cast(sum(case when HSNB in('治疗费') " +
                "then ORD_TOT_PRC else null end) / sum(ORD_TOT_PRC) * 100.0 as decimal(18,2)) as zlbl,");//--治疗比例

        sql.append(" cast(sum(case when HSNB in('材料费','手术费','注射费') " +
                "then ORD_TOT_PRC else null end) / sum(ORD_TOT_PRC) * 100.0 as decimal(18,2)) as qtbl ");//--其他比例

        sql.append(" from  CHRG_LIST_V  where CHRG_DT  BETWEEN '" + sd + "' AND '" + ed + "' and ORD_WIDE = '1' ");

        res = Db.use(xx.Ds.BS2).find(sql.toString());


        return res;
    } 

执行Db.use(xx.Ds.BS2).find(sql.toString())报:

 this = {Invocation@3857} 
e = {InvocationTargetException@3883} "java.lang.reflect.InvocationTargetException"
 target = {NoClassDefFoundError@3884} "java.lang.NoClassDefFoundError: org/apache/commons/lang/math/NumberUtils"
 detailMessage = null
 cause = null
 stackTrace = {StackTraceElement[0]@3850} 
 suppressedExceptions = {Collections$UnmodifiableRandomAccessList@3851}  size = 0
t = {NoClassDefFoundError@3884} "java.lang.NoClassDefFoundError: org/apache/commons/lang/math/NumberUtils"
 detailMessage = "org/apache/commons/lang/math/NumberUtils"
 cause = {NoClassDefFoundError@3884} "java.lang.NoClassDefFoundError: org/apache/commons/lang/math/NumberUtils"
 stackTrace = {StackTraceElement[0]@3850} 
 suppressedExceptions = {Collections$UnmodifiableRandomAccessList@3851}  size = 0 

提示没有找到lang包下的NumberUtils方法,是否是依赖包没下载?

评论区

JFinal

2016-10-12 18:47

jfinal 没有用过 NumberUtils 这个类,更没有用 apache 这个第三方,应该是你自己的项目中对该类有引用

lyh061619

2016-10-13 10:37

@JFinal 用Db.find做查询跑到这个com.jfinal.plugin.activerecord包下的SqlReporter类中的方法:
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
if (method.getName().equals("prepareStatement")) {
String info = "Sql: " + args[0];
if (logOn)
log.info(info);
else
System.out.println(info);
}
return method.invoke(conn, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
}
走到这里:method.invoke(conn, args);就抛异常了。

其中args参数是:
select cast(sum(case when HSNB in('成药费','西药费', '中药费','疫苗费') then ORD_TOT_PRC else null end) / sum(ORD_TOT_PRC) * 100.0 as decimal(18,2)) as ypbl, cast(sum(case when HSNB in('检查费','诊查费') then ORD_TOT_PRC else null end) / sum(ORD_TOT_PRC) * 100.0 as decimal(18,2)) as jcbl, cast(sum(case when HSNB in('治疗费') then ORD_TOT_PRC else null end) / sum(ORD_TOT_PRC) * 100.0 as decimal(18,2)) as zlbl, cast(sum(case when HSNB in('材料费','手术费','注射费') then ORD_TOT_PRC else null end) / sum(ORD_TOT_PRC) * 100.0 as decimal(18,2)) as qtbl from CHRG_LIST_V where CHRG_DT BETWEEN '2015-11-11 00:00:00' AND '2015-11-11 23:59:59' and ORD_WIDE = '1'

排查过程:
第一步JFinal追踪:提示lang包下NumberUtils没找到,这个工具类主要用作数据类型转换用的,从这点来判断肯定是JFinal 操作sqlserver数据库,执行操作过程中转换数据类型时报错了,但即使是自己手动添加apache commons lang下去也是解决不了,还是抛出异常,感觉还是不对头异常不成立。
第二步alibaba druid追踪,踪进入method.invoke方法进入FilterChainImpl类执行到这个方法:
public PreparedStatementProxy connection_prepareStatement(ConnectionProxy connection, String sql) throws SQLException {
if(this.pos < this.filterSize) {
return this.nextFilter().connection_prepareStatement(this, connection, sql);
} else {
PreparedStatement statement = connection.getRawObject().prepareStatement(sql);
return this.wrap(connection, statement, sql);
}
}
走到这里:this.nextFilter().connection_prepareStatement(this, connection, sql);就开始抛异常。
最终判断,alibaba druid 1.0.24 版本存sql server 连接数据在bug,立马换1.0.26最新版本再跑,问题解决了。^_^YY

JFinal

2016-10-13 10:49

@lyh061619 感谢解决问题后再次回来分享

lyh061619

2016-10-13 10:50

@JFinal 波总这个是必须的,支持JFinal支持社区发展。^_^^_^

热门反馈

扫码入社