我用db.user(db2).find另一个数据源返回的Record,想把本地的数据源abc对象对拷Record里面的字段(字段确保一一对应),我之前使用put是可以的,可是我把本地的数据源abd表增加了一个字段,put之前通过r.set("新增字段","xxxx"); 然后再put过去,就不好使了!请问什么问题呢?
补充:当我使用productRelSupplierProduct.setID(r.getStr("ID")); 把字段,一个一个set进去再批量保存,是能正常使用的!但是有近百个字段,这样好像不科学。。
解决办法:测试环境,相同的表面给别人增加了字段。
Record listProductRelSupplierProduct = Db.use("db2").find( "SELECT LOTS.PRODUCT_REL_SUPPLIER_PRODUCT.* FROM LOTS.PRODUCT_REL_SUPPLIER_PRODUCT WHERE LASTUPDATED > TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') OR CREATETIME > TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')", dictionaries.getValue(), dictionaries.getValue()); List<ProductRelSupplierProduct> listProductMstProductsSave = new ArrayList<>(); for (Record r : listProductRelSupplierProduct) { ProductRelSupplierProduct productRelSupplierProduct = ProductRelSupplierProduct.dao.findById(r.getStr("ID")); r.set("keyword","test");//新增字段 if (productRelSupplierProduct == null) { productRelSupplierProduct = new ProductRelSupplierProduct(); productRelSupplierProduct.put(r); //productRelSupplierProduct.setID(r.getStr("ID")); listProductMstProductsSave.add(productRelSupplierProduct); } else { productRelSupplierProduct.put(r); listProductMstProductsUpdate.add(productRelSupplierProduct); } } Db.batchSave(listProductMstProductsSave, listProductMstProductsSave.size());
错误提示:
com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: Parameter index out of range (95 > number of parameters, which is 94). at com.jfinal.plugin.activerecord.DbPro.batch(DbPro.java:1038) at com.jfinal.plugin.activerecord.DbPro.batchSave(DbPro.java:1135) at com.jfinal.plugin.activerecord.Db.batchSave(Db.java:619) at com.seo.goods.GoodsService.updateGoods(GoodsService.java:202) at com.seo.goods.GoodsController.updateProductMst(GoodsController.java:85) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.jfinal.aop.Invocation.invoke(Invocation.java:73) at com.seo.intercepter.StoreInterceptor.intercept(StoreInterceptor.java:20) at com.jfinal.aop.Invocation.invoke(Invocation.java:67) at com.seo.intercepter.LoginSessionInterceptor.intercept(LoginSessionInterceptor.java:45) at com.jfinal.aop.Invocation.invoke(Invocation.java:67) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:83) at com.seo.silian.SilianHandler.handle(SilianHandler.java:30) at com.seo.silian.SilianHandler.handle(SilianHandler.java:30) at com.jfinal.ext.handler.FakeStaticHandler.handle(FakeStaticHandler.java:58) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) at org.eclipse.jetty.server.Server.handle(Server.java:365) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485) at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926) at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Unknown Source) Caused by: java.sql.SQLException: Parameter index out of range (95 > number of parameters, which is 94). at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927) at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3754) at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3738) at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:4578) at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:3982) at com.alibaba.druid.pool.DruidPooledPreparedStatement.setObject(DruidPooledPreparedStatement.java:481) at com.jfinal.plugin.activerecord.DbPro.batch(DbPro.java:995) at com.jfinal.plugin.activerecord.DbPro.batch(DbPro.java:1036) ... 41 more
输出:put过去之后,列的数量是一样
logger.info("r 列:" + r.getColumns().size()); logger.info("保存prsp: " + r.getStr("ID")); productRelSupplierProduct.put(r); logger.info("本地ProductRelSupplierProduct:" + productRelSupplierProduct.toRecord().getColumns().size());
项目:JFinal