Java调用MySql数据库函数

Java调用MySql数据库函数

    /**
     * 调用mysql的自定义函数
     * 
     */
    private void test() {
        logger.info("show task start ");
        Connection conn = null;
        CallableStatement cs = null;
        try {
            conn = Pub.getConnMysql();
             //调用存储过程
            conn.setAutoCommit(false);
            cs = conn.prepareCall("{call " + db+ ".P_TEST()}");
            cs.executeQuery();
            conn.commit();
        }catch (Exception e) {
            logger.info("Exception: "+e.getMessage());
        }finally{
            try {
                cs.close();
            } catch (Exception ignore) {
                logger.info("Exception:"+ignore.getMessage());
                ignore.printStackTrace();
            }
            Pub.CloseConnect(conn);
        }
        logger.info("show task end ");
    }
posted @ 2019-12-24 15:41  整合侠  阅读(2166)  评论(0编辑  收藏  举报