在 java web 中调用存储过程

来源:互联网 发布:vb中for循环 编辑:程序博客网 时间:2024/05/21 11:31
/**     * 添加一个购物车对象,这个已经不用了     */    @Override    public boolean addCart(int userId,int prodId) {        Connection connection = null;        try {            connection = JDBCTools.getConnection();            String checkOrderSql = "{CALL `db_alishop`.checkOrder(?,?)}";            CallableStatement cstmt = connection.prepareCall(checkOrderSql);            cstmt.setInt(1, userId);            cstmt.setInt(2, prodId);            //cstmt.registerOutParameter(2, java.sql.Types.INTEGER);            cstmt.execute();            //int orderId = cstmt.getInt(2);            cstmt.close();        } catch (SQLException e) {            e.printStackTrace();        } finally {            JDBCTools.releaseDB(null, null, connection);        }        return false;    }    @Override    public boolean addProdToCartByAccount(String account,int prodId,int prodNum) {        Connection connection = null;        try {            connection = JDBCTools.getConnection();            String checkOrderSql = "{CALL db_alishop.`addProdByAccount`(?,?,?)}";            CallableStatement cstmt = connection.prepareCall(checkOrderSql);            cstmt.setString(1, account);            cstmt.setInt(2, prodId);            cstmt.setInt(3, prodNum);            cstmt.execute();            cstmt.close();            return true;        } catch (SQLException e) {            e.printStackTrace();        } finally {            JDBCTools.releaseDB(null, null, connection);        }        return false;    }    @Test    public void testaddProdToCartByAccount(){        addProdToCartByAccount("dan",7,1);    }
0 0
原创粉丝点击