java.lang.NullPointerException--at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement

使用druid封装了一下,传入数据库连接信息和sql语句进行执行,但偶尔报错,没找到规律,请大神们帮看看是什么原因?
相关网上的资料也按照配置过,问题还没没有得到解决
druid 连接池 close connection error问题通过配置testOnBorrow=true暂未重现
以下是报错信息,这个问题一直没得到解决

返回结果-------------:1
系统异常了CONN:com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@1b4197e1
系统异常了SQL:insert into ZFGL.BILLS_DETAIL ( f_timestamp  , BCODE , BILLNO , BILLSDETAILGUID , BNAME , ECODE , ECONOMYGUID , ENAME , ENTERPRISEGUID , FUNCTIONGUID , GOVECOGUID , GOVKCODE , GOVKNAME , GUID , INAME , KCODE , KNAME , PAYMODCODE , PAYMODID , PAYMODNAME , PROGRAMCODE , PROGRAMGUID , PROGRAMTYPECODE , PROGRAMTYPEID , PROGRAMTYPENAME , RELAID , RESOURCECODE , RESOURCEGUID , TOTALMONEY , TZMC , YEAR) values ( to_timestamp('2019-03-12 11:43:16.637953','yyyy-mm-dd hh24:mi:ss.ff6')  ,'2040601'  ,'2019010001000004'  ,''  ,'行XXXXX'  ,'010001'  ,'C3146047304548D1AAD0066E62595F52'  ,'克XXXX'  ,'037A71055FCD4FF882F7E575120FEEBD'  ,''  ,''  ,''  ,''  ,'ED494B52F7B249C5B6E24F52D92E12E7'  ,'公用支出'  ,'30XXXX'  ,'福XXXX'  ,'12'  ,'870517B306F94DFF84305120BCDC26B6'  ,'财政授权支付'  ,'00019992'  ,'34772B4128B14606982C532BCAB0316D'  ,'01'  ,'2F0DF49684EE465CBC28FD1CC908F140'  ,'基本支XX 76651498380024E0530A2CA82B62C8'  ,'11'  ,'7EF59F8C9FF7424989F4E3ED61254B4F'  ,'802.811223般公共XXXX' 19' )
java.lang.NullPointerException
    at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:350)
    at com.yicaida.dal.serviceimpl.DynamicConnServiceImpl.execSql(DynamicConnServiceImpl.java:295)
    at com.yicaida.dx.serviceimpl.DxServiceImpl.runApiNow(DxServiceImpl.java:332)
    at com.alibaba.dubbo.common.bytecode.Wrapper7.invokeMethod(Wrapper7.java)
    at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46)
    at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72)
    at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)
    at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:64)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:78)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:60)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:112)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:38)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:108)
    at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:84)
    at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:170)
    at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52)
    at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:82)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

源代码如下

public Integer execSql(DBInfoBean dbinfo, String sqlstr) {
        int result;
        PreparedStatement ps = null;
        try {
            conn = getConn(dbinfo);
            if (conn.isClosed() || conn == null) {
                conn = getConn(dbinfo);
            }
            ps = conn.prepareStatement(sqlstr);
            result = ps.executeUpdate();
        } catch (Exception err) {
            System.out.println("系统异常了CONN:" + conn);
            System.out.println("系统异常了SQL:" + sqlstr);
            err.printStackTrace();
            result = -1;
        } finally {
            if (ps != null) {
                try {
                    ps.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                    result = -1;
                }
            }
            close();
        }
        System.out.println("返回结果-------------:" + result);
        return result;
    }

1个回答

如果是概率性出现有可能操作系统在一段时间内把tcp的连接给断了,导致连接不可用,理论上来说testOnBorrow=true后,这个问题应该不会重现。
也可以使用testWhileIdle=true以及timeBetweenEvictionRunsMillis=60000这两个配置,这两个配置相对于testOnBorrow来,损耗会小点

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问