NutzCN Logo
问答 问一个关于调用存储过程的问题
发布于 24天前 作者 qq_5d7ceb9a 124 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

调用存储过程的时候,没有返回数据,打印的sql在数据库中是可以查到数据的,是我的回调写的有问题吗
https://nutz.cn/s/c/Wn

9 回复

这个存储过程有返回结果集?? 自定义一个SqlCallback试试

我之前是这么写的,我觉得好像是原生态,觉得咱们文档中的更简单 所以我就换了 但是没有数据,下面这个是可以的

ConnCallback callBack = new ConnCallback() {
			@Override
			public void invoke(Connection conn) throws Exception {
				CallableStatement statement = null;
				String sql = "call a_bsdkj(?,?,?,?,?,?,?,?,?)";	
				statement = conn.prepareCall(sql);
				statement.setString(1, sdate);
				statement.setString(2, edate);
				statement.setInt(3, traderidA);
				statement.setInt(4, goodsidA);
				statement.setInt(5, goodsidB);
				statement.setInt(6, empid);
				statement.setString(7, contractcode);
				statement.setInt(8, traderidB);
				statement.setInt(9, finished);
				
				ResultSet rs = statement.executeQuery();

				while (rs.next()) {
					Record record = Record.create(rs);
			
					batch x = new batch();
					for (int i = 1; i < rs.getMetaData().getColumnCount(); i++) {
						
						record.set(rs.getMetaData().getColumnName(i), rs.getObject(i));
						
						if(null != record.getString("billdate")){
							x.setBilldate(record.getString("billdate"));
						}else{
							x.setBilldate("");
						}
							
						if(null != record.getString("tradernamea")){
							x.setTradernamea(record.getString("tradernamea"));
						}else{
							x.setTradernamea("");
						}
							
						if(null != record.getString("contractcode")){
							x.setContractcode(record.getString("contractcode"));
						}else{
							x.setContractcode("");
						}
							
						if(null != record.getString("employname")){
							x.setEmployname(record.getString("employname"));
						}else{
							x.setEmployname("");
						}
							
						if(null != record.getString("goodscode")){
							x.setGoodscode(record.getString("goodscode"));
						}else{
							x.setGoodscode("");
						}
							
						if(null != record.getString("goodsname")){
							x.setGoodsname(record.getString("goodsname"));
						}else{
							x.setGoodsname("");
						}
							
						if(null != record.getString("goodstype")){
							x.setGoodstype(record.getString("goodstype"));
						}else{
							x.setGoodstype("");
						}
							
						if(null != record.getString("goodsuserdef1")){
							x.setGoodsuserdef1(record.getString("goodsuserdef1"));
						}else{
							x.setGoodsuserdef1("");
						}
							
						if(null != record.getString("goodsunit")){
							x.setGoodsunit(record.getString("goodsunit"));
						}else{
							x.setGoodsunit("");
						}
							
						if(null != record.getString("quantitya")){
							x.setQuantitya(new BigDecimal(record.getString("quantitya")).setScale(2, BigDecimal.ROUND_HALF_UP));
						}else{
							x.setQuantitya(new BigDecimal(record.getString("quantitya")).setScale(2, BigDecimal.ROUND_HALF_UP));
						}
							
						if(null != record.getString("pdate"))
							x.setPdate(record.getString("pdate"));
						if(null != record.getString("quantityb"))
							x.setQuantityb(new BigDecimal(record.getString("quantityb")).setScale(2, BigDecimal.ROUND_HALF_UP));
						if(null != record.getString("premark"))
							x.setPremark(record.getString("premark"));
						if(null != record.getString("tradernameb"))
							x.setTradernameb(record.getString("tradernameb"));
						if(null != record.getString("quantityc"))
							x.setQuantityc(new BigDecimal(record.getString("quantityc")).setScale(2, BigDecimal.ROUND_HALF_UP));
						if(null != record.getString("quantityd"))
							x.setQuantityd(new BigDecimal(record.getString("quantityd")).setScale(2, BigDecimal.ROUND_HALF_UP));				
						if(null != record.getString("quantitye"))
							x.setQuantitye(new BigDecimal(record.getString("quantitye")).setScale(2, BigDecimal.ROUND_HALF_UP));		
						if(null != record.getString("quantityf"))
							x.setQuantityf(new BigDecimal(record.getString("quantityf")).setScale(2, BigDecimal.ROUND_HALF_UP));		
						if(null != record.getString("quantitye"))
							x.setQuantitye(new BigDecimal(record.getString("quantitye")).setScale(2, BigDecimal.ROUND_HALF_UP));		
						if(null != record.getString("iremark"))
							x.setIremark(record.getString("iremark"));
						if(null != record.getString("quantityg"))
							x.setQuantityg(new BigDecimal(record.getString("quantityg")).setScale(2, BigDecimal.ROUND_HALF_UP));	
						if(null != record.getString("quantityh"))
							x.setQuantityh(new BigDecimal(record.getString("quantityh")).setScale(2, BigDecimal.ROUND_HALF_UP));		
						if(null != record.getString("quantityi"))
							x.setQuantitye(new BigDecimal(record.getString("quantityi")).setScale(2, BigDecimal.ROUND_HALF_UP));		
						if(null != record.getString("onhand"))
							x.setOnhand(new BigDecimal(record.getString("onhand")).setScale(2, BigDecimal.ROUND_HALF_UP));		
						if(null != record.getString("finished")){
							if(record.getString("finished").equals("0")){
								x.setFinished(false);
							}else{
								x.setFinished(true);
							}
						}
					
					
					}
					list.add(x);
				}
			}
		};
		dao().run(callBack);*/
		return list;
	}

哦,你是当查询用

那就加一句sql.forceQuery(),在execute之前

来自炫酷的 NutzCN

结果还是[]集合

Sql sql = Sqls.create("exec a_bsdkj @begindate,@enddate,@traderAID,@traderBID,@goodsAID,@goodsBID,@employID,@contractcode,@finished");
		   
			sql.params().set("begindate",sdate); //设置入参
		    sql.params().set("enddate",edate); //设置入参
		    sql.params().set("traderAID",1); //设置入参
		    sql.params().set("traderBID",1); //设置入参
		    sql.params().set("goodsAID",1); //设置入参
		    sql.params().set("goodsBID",1); //设置入参
		    sql.params().set("employID",contractcode); //设置入参
		    sql.params().set("contractcode",1); //设置入参
		    sql.params().set("finished",1); //设置入参
		    
		    

		    System.err.println("sql = "+sql);
		   
		    sql.setCallback(Sqls.callback.entities());
		    sql.setEntity(dao().getEntity(batch.class));
		    
		    
		    sql.forceExecQuery();
		    dao().execute(sql);
		    
		   
		    
		    List<batch> list = sql.getList(batch.class);
		    System.err.println(Json.toJson(list));

我把日志贴出来吧

2018-10-26 15:22:23,321 com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1057) DEBUG - skip not validate connection.
2018-10-26 15:22:23,488 org.nutz.dao.impl.jdbc.AbstractJdbcExpert.setupEntityField(AbstractJdbcExpert.java:108) DEBUG - Table '#result' doesn't exist!
2018-10-26 15:22:23,489 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - select  distinct name as tradernamea ,traderid as traderidA from l_trader where isclient = 1
2018-10-26 15:22:23,492 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - select  distinct name as tradernameb ,traderid as traderidB from l_trader where isvendor = 1
2018-10-26 15:22:23,493 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - select  distinct billcode as contractcode from S_Order
2018-10-26 15:22:23,495 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - select  distinct name as goodsname ,goodsid as goodsidA  from l_goods
2018-10-26 15:22:23,496 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - select  distinct code as goodscode,goodsid as goodsidB  from l_goods
2018-10-26 15:22:23,498 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - select  distinct empid,name as employname from L_EMPLOY
2018-10-26 15:22:23,499 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'toolkit'<class com.bsdkj.reportapp.common.util.Toolkit>
2018-10-26 15:22:23,500 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - 	 >> Load definition name=toolkit
2018-10-26 15:22:23,500 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) DEBUG - Found IocObject(toolkit) in AnnotationIocLoader(packages=[com.bsdkj.reportapp])
2018-10-26 15:22:23,500 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - 	 >> Make...'toolkit'<class com.bsdkj.reportapp.common.util.Toolkit>
2018-10-26 15:22:23,500 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class com.bsdkj.reportapp.common.util.Toolkit without AOP
2018-10-26 15:22:23,500 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) DEBUG - Save object 'toolkit' to [app] 
2018-10-26 15:22:23,503 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dateUtils'<class com.bsdkj.reportapp.common.util.DateUtils>
2018-10-26 15:22:23,503 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - 	 >> Load definition name=dateUtils
2018-10-26 15:22:23,503 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) DEBUG - Found IocObject(dateUtils) in AnnotationIocLoader(packages=[com.bsdkj.reportapp])
2018-10-26 15:22:23,503 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - 	 >> Make...'dateUtils'<class com.bsdkj.reportapp.common.util.DateUtils>
2018-10-26 15:22:23,503 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class com.bsdkj.reportapp.common.util.DateUtils without AOP
2018-10-26 15:22:23,504 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) DEBUG - Save object 'dateUtils' to [app] 
2018-10-26 15:22:23,510 org.apache.velocity.runtime.log.SimpleLog4JLogSystem.logVelocityMessage(SimpleLog4JLogSystem.java:155) DEBUG - ResourceManager : found /WEB-INF/template/private/batch/index.html with loader org.apache.velocity.runtime.resource.loader.FileResourceLoader
2018-10-26 15:22:23,521 org.apache.velocity.runtime.log.SimpleLog4JLogSystem.logVelocityMessage(SimpleLog4JLogSystem.java:155) DEBUG - Null reference [template '/WEB-INF/template/private/batch/index.html', line 211, column 53] : $dp cannot be resolved.
2018-10-26 15:22:23,521 org.apache.velocity.runtime.log.SimpleLog4JLogSystem.logVelocityMessage(SimpleLog4JLogSystem.java:155) DEBUG - Null reference [template '/WEB-INF/template/private/batch/index.html', line 211, column 57] : $D cannot be resolved.
2018-10-26 15:22:23,521 org.apache.velocity.runtime.log.SimpleLog4JLogSystem.logVelocityMessage(SimpleLog4JLogSystem.java:155) DEBUG - Null reference [template '/WEB-INF/template/private/batch/index.html', line 221, column 53] : $dp cannot be resolved.
2018-10-26 15:22:23,521 org.apache.velocity.runtime.log.SimpleLog4JLogSystem.logVelocityMessage(SimpleLog4JLogSystem.java:155) DEBUG - Null reference [template '/WEB-INF/template/private/batch/index.html', line 221, column 57] : $D cannot be resolved.
2018-10-26 15:22:23,522 org.apache.velocity.runtime.log.SimpleLog4JLogSystem.logVelocityMessage(SimpleLog4JLogSystem.java:155) DEBUG - Null reference [template '/WEB-INF/template/private/batch/index.html', line 211, column 53] : $dp cannot be resolved.
2018-10-26 15:22:23,523 org.apache.velocity.runtime.log.SimpleLog4JLogSystem.logVelocityMessage(SimpleLog4JLogSystem.java:155) DEBUG - Null reference [template '/WEB-INF/template/private/batch/index.html', line 211, column 57] : $D cannot be resolved.
2018-10-26 15:22:23,523 org.apache.velocity.runtime.log.SimpleLog4JLogSystem.logVelocityMessage(SimpleLog4JLogSystem.java:155) DEBUG - Null reference [template '/WEB-INF/template/private/batch/index.html', line 221, column 53] : $dp cannot be resolved.
2018-10-26 15:22:23,523 org.apache.velocity.runtime.log.SimpleLog4JLogSystem.logVelocityMessage(SimpleLog4JLogSystem.java:155) DEBUG - Null reference [template '/WEB-INF/template/private/batch/index.html', line 221, column 57] : $D cannot be resolved.
2018-10-26 15:22:23,524 com.bsdkj.reportapp.common.mvc.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) DEBUG - [GET ]URI=/reportapp/report/index 250ms
2018-10-26 15:22:25,261 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [POST] path=/report/search : batch_action.list(batch_action.java:76)
2018-10-26 15:22:25,261 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'batch_action'<class com.bsdkj.reportapp.modules.mvc.batch_action>
sdate:
edate:
traderidA:null
goodsidA:null
goodsidB:null
empid:null
contractcode:
traderidB:null
finished:null
sql = exec a_bsdkj '','',1,1,1,1,'',1,1
2018-10-26 15:22:25,282 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - exec a_bsdkj ?,?,?,?,?,?,?,?,?
    | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
    |--|--|---|---|---|---|--|---|---|
    |  |  | 1 | 1 | 1 | 1 |  | 1 | 1 |
  For example:> "exec a_bsdkj '','',1,1,1,1,'',1,1"
2018-10-26 15:22:25,283 org.nutz.dao.impl.sql.run.NutDaoExecutor._runExec(NutDaoExecutor.java:118) DEBUG - exec a_bsdkj ?,?,?,?,?,?,?,?,?
[]
[]
2018-10-26 15:22:25,331 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'toolkit'<class com.bsdkj.reportapp.common.util.Toolkit>
2018-10-26 15:22:25,331 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dateUtils'<class com.bsdkj.reportapp.common.util.DateUtils>
2018-10-26 15:22:25,338 org.apache.velocity.runtime.log.SimpleLog4JLogSystem.logVelocityMessage(SimpleLog4JLogSystem.java:155) DEBUG - ResourceManager : found /WEB-INF/template/private/batch/list.html with loader org.apache.velocity.runtime.resource.loader.FileResourceLoader
2018-10-26 15:22:25,341 com.bsdkj.reportapp.common.mvc.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) DEBUG - [POST]URI=/reportapp/report/search 80ms
String sql = "call a_bsdkj(?,?,?,?,?,?,?,?,?)";	
"exec a_bsdkj '','',1,1,1,1,'',1,1"

不一样呀?

call

2018-10-26 15:38:09,096 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - call a_bsdkj (?,?,?,?,?,?,?,?,?)
    | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
    |--|--|---|---|---|---|--|---|---|
    |  |  | 1 | 1 | 1 | 1 |  | 1 | 1 |
  For example:> "call a_bsdkj ('','',1,1,1,1,'',1,1)"
2018-10-26 15:38:09,097 org.nutz.dao.impl.sql.run.NutDaoExecutor._runExec(NutDaoExecutor.java:118) DEBUG - call a_bsdkj (?,?,?,?,?,?,?,?,?)
[]
[]

call a_bsdkj ('','',1,1,1,1,'',1,1)这条数据不是直接在数据库中查不出数据么 我就改了一下嘛

@wendal 大佬,能帮忙看看吗?

自定义回调试试吧,也许是多个resultset了

来自炫酷的 NutzCN

添加回复
请先登陆
回到顶部