@JFinal 你好,想跟你请教个问题:
我用的是1.8版本 , 今有一需求做一个批量保存功能,运行报错,怎么会提示索引超出范围?
详情,如下:
Sql:
com.jfinal.plugin.activerecord.ActiveRecordException: com.microsoft.sqlserver.jdbc.SQLServerException: 索引 1 超出范围。
at com.jfinal.plugin.activerecord.DbPro.batch(DbPro.java:860)
at com.jfinal.plugin.activerecord.Db.batch(Db.java:488)
at com.demo.qa.Qa_Controll.saveBatch(Qa_Controll.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.jfinal.core.ActionInvocation.invoke(ActionInvocation.java:55)
at com.jfinal.plugin.activerecord.tx.Tx.intercept(Tx.java:76)
at com.jfinal.core.ActionInvocation.invoke(ActionInvocation.java:51)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:73)
at com.demo.common.MyContextPathHandler.handle(MyContextPathHandler.java:31)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 索引 1 超出范围。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:130)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setterGetParam(SQLServerPreparedStatement.java:667)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setObjectNoType(SQLServerPreparedStatement.java:852)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setObject(SQLServerPreparedStatement.java:875)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setObject(NewProxyPreparedStatement.java:365)
at com.jfinal.plugin.activerecord.DbPro.batch(DbPro.java:818)
at com.jfinal.plugin.activerecord.DbPro.batch(DbPro.java:858)
... 24 more
代码如下:
String sql ="";
QA_det3 dt1=new QA_det3();
dt1.set("dh", "test-001001");
dt1.set("iFPS_id", 1);
dt1.remove("id");
QA_det3 dt2=new QA_det3();
dt2.set("dh", "test-001001");
dt2.set("iFPS_id", 2);
dt2.remove("id");
List<QA_det3> modelOrRecordList=new ArrayList<QA_det3>();
modelOrRecordList.add(dt1);
modelOrRecordList.add(dt2);
try {
int[] result = Db.batch(sql, "dh,iFPS_id,nD1,nD2", modelOrRecordList, 1);
setAttr("flag", 1);
setAttr("msgText", "保存成功,请核对!");
renderJson();
} catch (Exception e) {
e.printStackTrace();
setAttr("flag", 0);
setAttr("msgText", "保存失败,请核对!");
renderJson();
}
sql是""空串,自然会有问题,建议使用jfinal新版本的Db.batchSave(...)可以免去sql
sql要写成:"InsertintoXXX(dh,iFps_id,nD1,nD2)values(?,?,?,?) "吗?,那如果批量里面有增删改这几种情况,又如何批量操作呢?
将鼠标停留在batch系列方法之上,然后会出来注释内容,注释里面有例子代码,参考着写就可以了sql是""空串,自然会有问题,建议使用jfinal新版本的Db.batchSave(...)可以免去sql
1.8中注释里没看到有例子代码
明白了,自已分类处理这几种情况即可,谢谢.
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。