NutzCN Logo
问答 自定义sql参数为list 报错
发布于 102天前 作者 qq_93105859 191 次浏览 复制 上一个帖子 下一个帖子
标签:

代码:

List<Long> list = new ArrayList<>();
		list.add(1L);
		list.add(16L);
		list.add(5L);
		sql.params().set("createNptId", list);

报错如下:

六月 11, 2019 1:51:41 下午 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter [nutz]
org.nutz.mvc.LoadingException: org.nutz.dao.DaoException: java.lang.ArrayIndexOutOfBoundsException: 8
	at org.nutz.mvc.LoadingException$FC$9167ef66dcfbd4806c561881c219e031.invoke(LoadingException.java)
	at org.nutz.lang.born.AbstractConstructorBorning.call(AbstractConstructorBorning.java:25)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:19)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:1022)
	at org.nutz.lang.Lang.wrapThrow(Lang.java:203)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:135)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:91)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:69)
	at com.zq.ums.biz.web.filter.BizFilter.init(BizFilter.java:30)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:266)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4637)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5282)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1140)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.dao.DaoException: java.lang.ArrayIndexOutOfBoundsException: 8
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:140)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:93)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:82)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:252)
	at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:236)
	at org.nutz.dao.impl.NutDao.execute(NutDao.java:1013)
	at com.zq.ums.biz.service.impl.common.InitServiceImpl.cusCache(InitServiceImpl.java:224)
	at com.zq.ums.biz.service.impl.common.InitServiceImpl.init(InitServiceImpl.java:71)
	at com.zq.ums.biz.MainSetup.init(MainSetup.java:48)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:278)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:121)
	... 20 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 8
	at org.nutz.dao.impl.sql.NutSql$SqlParamPItem$1.invoke(NutSql.java:315)
	at org.nutz.lang.Lang.each(Lang.java:1609)
	at org.nutz.lang.Lang.each(Lang.java:1563)
	at org.nutz.dao.impl.sql.NutSql$SqlParamPItem.joinAdaptor(NutSql.java:313)
	at org.nutz.dao.impl.sql.NutSql.getAdaptors(NutSql.java:112)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:259)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:53)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at com.zq.ums.biz.aop.UpdateDaoInterceptor.filter(UpdateDaoInterceptor.java:46)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.impl.interceptor.DaoTimeInterceptor.filter(DaoTimeInterceptor.java:23)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:159)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:126)
	... 31 more

六月 11, 2019 1:51:41 下午 org.apache.catalina.core.StandardContext startInternal
严重: One or more Filters failed to start. Full details will be found in the appropriate container log file
六月 11, 2019 1:51:41 下午 org.apache.catalina.core.StandardContext startInternal
严重: Context [/ums.biz] startup failed due to previous errors
六月 11, 2019 1:51:41 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
警告: The web application [ums.biz] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
六月 11, 2019 1:51:41 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
警告: The web application [ums.biz] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
六月 11, 2019 1:51:41 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
警告: The web application [ums.biz] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
六月 11, 2019 1:51:41 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
9 回复

批量执行? 用sql.addBatch(), 而不是用list

@wendal 我没看明白意思,这里是应该怎么改呢?

Sql sql = Sqls.create....
sql.setParam("a", 1);
sql.addBatch();
sql.setParam("a", 2);
sql.addBatch();
dao.execute(sql);

这是代码片段

" LEFT JOIN (SELECT temp8.course_id,COUNT(temp8.course_id) pay_count FROM fin_occur_item temp8 WHERE temp8.create_npt_id IN (@createNptId) GROUP BY temp8.course_id) t9  ON t9.course_id=t1.course_id AND t1.debit=-1";
		Sql sql = Sqls.create(sqlStr);
		sql.setCallback(Sqls.callback.entities());
		sql.setEntity(dao.getEntity(VStatisticsReceivAndPay.class));
		List<Long> list = new ArrayList<>();
		list.add(1L);
		list.add(16L);
		list.add(5L);
		sql.params().set("createNptId", list);
		sql.addBatch();
		dao.execute(sql);
		List<VStatisticsReceivAndPay> result = sql.getList(VStatisticsReceivAndPay.class);

哦,我明白了,谢谢

@wendal 还是不对
这是生成的sql片段:

temp2.verification_status=20 AND temp2.create_npt_id IN (1) GROUP BY temp2.course_id) t3  ON t3.cou

in后面的括号里只有一个,我代码这样写的:

Sql sql = Sqls.create(sqlStr);
		sql.setCallback(Sqls.callback.entities());
		sql.setEntity(dao.getEntity(VStatisticsReceivAndPay.class));
		List<Long> list = new ArrayList<>();
		list.add(1L);
		list.add(16L);
		list.add(5L);
		sql.setParam("createNptId", 1);
		sql.addBatch();
		sql.setParam("createNptId", 16);
		sql.addBatch();
		sql.setParam("createNptId", 15);
		sql.addBatch();
		dao.execute(sql);

应该是有3个才对

哦, 是in, 用数组吧, 去掉addBatch的东西, 把最初的代码改一下, list改成数组

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