程序多次运行后报错listener could not hand off client connection

Jfinal框架开发的一个调用存储过程,程序执行多次后报错listener could not hand off client connection,第一次用Jfinal,查了许多资料,没找到解决方案,请大神帮忙看看。

具体代码:

package com.cnnp.usopp.controller;

import java.math.BigDecimal;

import java.sql.CallableStatement;

import java.sql.Connection;

import java.sql.SQLException;

import java.util.HashMap;

import java.util.Map;

import com.jfinal.core.Controller;

import com.jfinal.kit.PropKit;

import com.jfinal.plugin.activerecord.Db;

import com.jfinal.plugin.activerecord.DbKit;

import com.jfinal.plugin.activerecord.ICallback;

import com.jfinal.plugin.activerecord.Record;

import static com.sun.tools.javac.util.StringUtils.toUpperCase;

public class SearchInventPurchase extends Controller {

    public void getlist() {

        //定义参数 订单号、行号、下达号、接收数量(前台传入手工值)

        String params1 = getPara("order_no");

        String params2 = getPara("line_no");

        String params3 = getPara("release_no");

        String params4 = getPara("qty");

        System.out.println(params1);

        System.out.println(params2);

        System.out.println(params3);

        //sql语句

 String sql = "select ORDER_NO, LINE_NO, RELEASE_NO, ifsapp.PURCHASE_RECEIVE_CASE_API.Decode(RECEIVE_CASE_DB) RECEIVE_CASE, nvl(ENG_CHG_LEVEL, 1) ENG_CHG_LEVEL, PART_NO, LOT_BATCH_NO, nvl(SERIAL_NO, '*') SERIAL_NO, nvl(CONDITION_CODE, '') CONDITION_CODE, QC_CODE, NOTE_TEXT, CONTRACT, nvl(ACTIVITY_SEQ, 0) ACTIVITY_SEQ, contract, INPUT_VARIABLE_VALUES, ifsapp.Purchase_Order_Line_Part_API.Get_Default_Location_No(ORDER_NO, LINE_NO, RELEASE_NO) LOCATION_NO, ifsapp.INSPECTION_RULE_api.Get_Sample_Percent(INSPECTION_CODE)/100 QTY_TO_INSPECT, to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') ARRIVAL_DATE, decode(ifsapp.Inventory_Flag_API.Encode(ifsapp.PURCHASE_PART_API.Get_Inventory_Flag(CONTRACT,PART_NO)),'Y','TRUE','FALSE') INVENTORY_PART, DUE_AT_DOCK QTY_ARRIVED, CONV_FACTOR INV_QTY_ARRIVED, CONV_FACTOR QTY_ARRIVED_CONV_FACTOR from ifsapp.PURCHASE_ORDER_LINE_NEW where order_no = '" + params1 + "' and LINE_NO = " + params2 + " and RELEASE_NO = " + params3;

        // 获取到连接

        System.out.println(sql);

        Record record = Db.use("oracle").findFirst(sql);

        final StringBuilder Str = new StringBuilder();

        //获取字段值,并将字段值按照存储过程中的格式拼接

        if (record.getStr("INVENTORY_PART").equals("TRUE")) {

            Str.append("!" + "\n"

                    + "$ENG_CHG_LEVEL=" + record.getStr("ENG_CHG_LEVEL") + "\n"

                    + "$ORDER_NO=" + record.getStr("ORDER_NO") + "\n"

                    + "$LINE_NO=" + record.getStr("LINE_NO") + "\n"

                    + "$RELEASE_NO=" + record.getStr("RELEASE_NO") + "\n"

                    + "$RECEIPT_REFERENCE=" + "\n"

                    + "$RECEIVER=" +"SZWH_FG01"+ "\n"

                    + "$QTY_ARRIVED=" + (record.getBigDecimal("QTY_ARRIVED").compareTo(BigDecimal.valueOf(Integer.valueOf(params4))) == 0 ? record.getBigDecimal("QTY_ARRIVED"):params4) + "\n"

                    + "$INV_QTY_ARRIVED=" + record.getBigDecimal("INV_QTY_ARRIVED").multiply(BigDecimal.valueOf(Integer.valueOf(params4))) + "\n"

                    + "$CATCH_QTY_ARRIVED=" + "\n"

                    + "$QTY_TO_INSPECT=" + record.getBigDecimal("QTY_TO_INSPECT").multiply(BigDecimal.valueOf(Integer.valueOf(params4))) + "\n"

                    + "$ARRIVAL_DATE=" + record.getStr("ARRIVAL_DATE") + "\n"

                    + "$RECEIVE_CASE=" + record.getStr("RECEIVE_CASE") + "\n"

                    + "$INPUT_VARIABLE_VALUES=" + (record.getStr("INPUT_VARIABLE_VALUES") == null ? "" : record.getStr("INPUT_VARIABLE_VALUES")) + "\n"

                    + "$NOTE_TEXT=" + (record.getStr("NOTE_TEXT") == null ? "" : record.getStr("NOTE_TEXT")) + "\n"

                    + "$QC_CODE=" + (record.getStr("QC_CODE") == null ? "" : record.getStr("QC_CODE")) + "\n"

                    + "$CONTRACT=" + record.getStr("CONTRACT") + "\n"

                    + "$ACTIVITY_SEQ=" + record.getBigDecimal("ACTIVITY_SEQ") + "\n"

                    + "$PART_NO=" + record.getStr("PART_NO") + "\n"

                    + "$EXPIRATION_DATE=" + "\n"

                    + "$INVENTORY_PART=" + record.getStr("INVENTORY_PART") + "\n"

                    + "$LOCATION_NO=" + (record.getStr("LOCATION_NO") == null?"IQC":record.getStr("LOCATION_NO")) + "\n"

                    + "$LOT_BATCH_NO=" + record.getStr("LOT_BATCH_NO") + "\n"

                    + "$SERIAL_NO=" + "*" + "\n"

                    + "$CONDITION_CODE=" + (record.getStr("CONDITION_CODE") == null ? "" : record.getStr("CONDITION_CODE")) + "\n"

                    + "$WAIV_DEV_REJ_NO=" + "*" + "\n");

        } else {

            Str.append("!" + "\n"

                    + "$ORDER_NO=" + record.getStr("ORDER_NO") + "\n"

                    + "$LINE_NO=" + record.getStr("LINE_NO") + "\n"

                    + "$RELEASE_NO=" + record.getStr("RELEASE_NO") + "\n"

                    + "$RECEIPT_REFERENCE=" + "\n"

                    + "$RECEIVER=" + "SZWH_FG01" + "\n"

                    + "$QTY_ARRIVED=" + (record.getBigDecimal("QTY_ARRIVED").compareTo(BigDecimal.valueOf(Integer.valueOf(params4))) == 0 ? record.getBigDecimal("QTY_ARRIVED"):params4) + "\n"

                    + "$INV_QTY_ARRIVED=" + record.getBigDecimal("INV_QTY_ARRIVED").multiply(BigDecimal.valueOf(Integer.valueOf(params4))) + "\n"

                    + "$CATCH_QTY_ARRIVED=" + "\n"

                    + "$QTY_TO_INSPECT=" + record.getBigDecimal("QTY_TO_INSPECT").multiply(BigDecimal.valueOf(Integer.valueOf(params4))) + "\n"

                    + "$ARRIVAL_DATE=" + record.getStr("ARRIVAL_DATE") + "\n"

                    + "$RECEIVE_CASE=" + record.getStr("RECEIVE_CASE") + "\n"

                    + "$INPUT_VARIABLE_VALUES=" + (record.getStr("INPUT_VARIABLE_VALUES") == null ? "" : record.getStr("INPUT_VARIABLE_VALUES")) + "\n"

                    + "$NOTE_TEXT=" + (record.getStr("NOTE_TEXT") == null ? "" : record.getStr("NOTE_TEXT")) + "\n"

                    + "$QC_CODE=" + (record.getStr("QC_CODE") == null ? "" : record.getStr("QC_CODE")) + "\n"

                    + "$CONTRACT=" + record.getStr("CONTRACT") + "\n"

                    + "$ACTIVITY_SEQ=" + record.getBigDecimal("ACTIVITY_SEQ") + "\n"

                    + "$PART_NO=" + record.getStr("PART_NO") + "\n"

                    + "$EXPIRATION_DATE=" + "\n");

        }

        final Map<String, Object> map = new HashMap<String, Object>();

        Db.use("oracle").execute(new ICallback() {

            @Override

            public Object call(Connection connection) throws SQLException {

                CallableStatement proc = null;

                try {

                    proc = connection.prepareCall("{call ifsapp.Receive_Purchase_Order_API.Packed_Arrival__(?,?,?,?,?,?,?,?)}");

                    proc.setString(6, Str.toString());

                    proc.setString(7, "false");

                    proc.setString(8, "false");

                    proc.registerOutParameter(1, java.sql.Types.VARCHAR);

                    proc.registerOutParameter(2, java.sql.Types.VARCHAR);

                    proc.registerOutParameter(3, java.sql.Types.VARCHAR);

                    proc.registerOutParameter(4, java.sql.Types.VARCHAR);

                    proc.registerOutParameter(5, java.sql.Types.VARCHAR);

                    //执行调用

                    proc.execute();

                    map.put("INFO", proc.getString(1));

                    map.put("ARRIVAL_RESULT_KEYS", proc.getString(2));

                    map.put("BAR_CODES", proc.getString(3));

                    map.put("RECEIPT_INFO", proc.getString(4));

                    map.put("AP_INVOICE_NO", proc.getString(5));

                } catch (Exception e) {

                    e.printStackTrace();

                } finally {

                    if (proc != null) {

                        proc.close();

                    }

                    if (connection !=null){

                        connection.close();

                    }

                }

                return null;

            }

        });

        renderJson("status", 0);

    }

}


评论区

JFinal

2019-01-29 17:04

代码不全,这个不好猜

存储过程要这么来用:
Db.execute((connection) -> {
CallableStatement cs = connection.prepareCall(...);
cs.setObject(1, ...);
cs.setObject(2, ...);
cs.execute();
cs.close();
return cs.getObject(1);
});

Jfinal_Home

2019-01-30 10:17

@JFinal 具体代码已经放上去,大神帮分析一下,谢谢

JFinal

2019-01-30 11:09

去掉 connection.close()

此外代码严重有问题,业务逻辑放业务层,复杂 sql 用 jfinal 的 sql 管理功能

热门反馈

扫码入社