有nutz52版本,如何调用,call assetscan.generate_orderNo('JX', 8, @newOrderNo);
并且返回@newOrderNo?????
可以提供一下代码吗?
// Mysql支持存储过程
@Test
public void test_simple_mysql_exec() {
if (!dao.meta().isMySql())
return; // Only test for mysql now
dao.create(Pet.class, true);
dao.insert(Pet.create("wendal"));
dao.execute(Sqls.create("DROP PROCEDURE IF EXISTS proc_pet_getCount"));
dao.execute(Sqls.create("CREATE PROCEDURE proc_pet_getCount()\nBEGIN\n\tSELECT name FROM t_pet;\nEND"));
Sql sql = Sqls.fetchString("CALL proc_pet_getCount()"); // 单一结果集,且没有输入输出参数
dao.execute(sql);
assertEquals("wendal", sql.getString());
}
// Mysql支持存储过程
@Test
public void test_simple_mysql_exec2() {
if (!dao.meta().isMySql())
return; // Only test for mysql now
dao.create(Pet.class, true);
dao.insert(Pet.create("wendal"));
dao.execute(Sqls.create("DROP PROCEDURE IF EXISTS proc_pet_fetch"));
dao.execute(Sqls.create("CREATE PROCEDURE proc_pet_fetch(IN nm varchar(1024))\nBEGIN\n\tSELECT * FROM t_pet where name=nm;\nEND"));
Sql sql = Sqls.fetchEntity("CALL proc_pet_fetch(@nm)");
sql.setEntity(dao.getEntity(Pet.class));
sql.params().set("nm", "wendal");
dao.execute(sql);
Pet pet = sql.getObject(Pet.class);
assertNotNull(pet);
assertEquals("wendal", pet.getName());
}
搞不懂?
CREATE DEFINER=root
@localhost
PROCEDURE generate_orderNo
(in orderNamePre char(2), in num int, out newOrderNo varchar(25))
BEGIN
DECLARE currentDate varCHAR (15) ;-- 当前日期,有可能包含时分秒
DECLARE maxNo INT DEFAULT 0 ; -- 离现在最近的满足条件的订单编号的流水号最后5位,如:SH2013011000002的maxNo=2
-- DECLARE l_orderNo varCHAR (25) ;-- 新生成的订单编号
-- DECLARE oldDate DATE ;-- 离现在最近的满足条件的订单编号的日期
DECLARE oldOrderNo VARCHAR (25) DEFAULT '' ;-- 离现在最近的满足条件的订单编号
if num = 8 then -- 根据年月日生成订单编号
SELECT DATE_FORMAT(NOW(), '%Y%m%d') INTO currentDate ;-- 订单编号形式:前缀+年月日+流水号,如:SH2013011000002
elseif num = 14 then -- 根据年月日时分秒生成订单编号
SELECT DATE_FORMAT(NOW(), '%Y%m%d%H%i%s') INTO currentDate ; -- 订单编号形式:前缀+年月日时分秒+流水号,如:SH2013011010050700001,个人不推荐使用这种方法生成流水号
else -- 根据年月日时分生成订单编号
SELECT DATE_FORMAT(NOW(), '%Y%m%d%H%i') INTO currentDate ;-- 订单形式:前缀+年月日时分+流水号,如:SH20130110100900005
end if ;
SELECT IFNULL(taskCode, '') INTO oldOrderNo
FROM ASSETSCANTASK
WHERE SUBSTRING(taskCode, 3, num) = currentDate
AND SUBSTRING(taskCode, 1, 2) = orderNamePre
and length(taskCode) = 7 + num
ORDER BY id DESC LIMIT 1 ; -- 有多条时只显示离现在最近的一条
IF oldOrderNo != '' THEN
SET maxNo = CONVERT(SUBSTRING(oldOrderNo, -5), DECIMAL) ;-- SUBSTRING(oldOrderNo, -5):订单编号如果不为‘‘截取订单的最后5位
END IF ;
SELECT
CONCAT(orderNamePre, currentDate, LPAD((maxNo + 1), 5, '0')) INTO newOrderNo ; -- LPAD((maxNo + 1), 5, '0'):如果不足5位,将用0填充左边
END
我的存储过程是这样的?如何在程序里返回newOrderNo?
看不懂就下面的jdbc方式吧, 简单暴力, 爱咋写就咋写
dao.run(new ConnCallback() {
@Override
public void invoke(Connection conn) throws Exception {
// TODO Auto-generated method stub
}
});
/**
* geneOrderNo : 获取任务单号
*
* @return
*/
public String geneOrderNo() {
String orderNo = "";
ConnCallback callBack = new ConnCallback() {
@Override
public void invoke(Connection conn) throws Exception {
CallableStatement statement = null;
String sql = "{call generate_orderNo(?,?,?)}";
statement = conn.prepareCall(sql);
statement.setString(1, "JX");
statement.setInt(2, 8);
statement.registerOutParameter(3, Types.VARCHAR);
statement.executeUpdate();
String orderNo = statement.getString(3);
System.out.println(orderNo);
}
};
this.assetScanDao.dao().run(callBack);
return orderNo;
}
感觉这样也不行吧,orderNo无法赋值?