batchSave(tablename,list,num) 多数据源解析问题

JfinalConfig.class
     	/**
	 * 配置插件
	 */
	@Override
	public void configPlugin(Plugins me) {
		//postgre
		DruidPlugin druidPlugin = new DruidPlugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password"));
		druidPlugin.addFilter(new StatFilter());
		me.add(druidPlugin);
		ActiveRecordPlugin arp = new ActiveRecordPlugin("post",druidPlugin);
		arp.setDialect(new PostgreSqlDialect());
		me.add(arp);
		//sqlserver
		DruidPlugin druidPlugin3= new DruidPlugin(getProperty("jdbcUrl3"), getProperty("username3"), getProperty("password3").trim() );
        me.add(druidPlugin3);
        ActiveRecordPlugin arp3 = new ActiveRecordPlugin("sqls",druidPlugin3);
        arp3.setContainerFactory(new CaseInsensitiveContainerFactory());
        arp3.setDialect(new SqlServerDialect());  
        me.add(arp3);
	}    
---------------------     
db_config.properties  文件
    jdbcUrl = jdbc:postgresql://172.18.1.4:5432/test 
    user = postgres
    password = trechina
    devMode = true
    
    #sqlsever Stone db
    jdbcUrl3:jdbc:sqlserver://192.168.8.7:1433;DatabaseName=DB_ROCKY_B_001
    username3:sa
    password3:sa
    jdbc.bireport.driverClassName = com.microsoft.sqlserver.jdbc.SQLServerDriver
--------------------------------     
 使用方法类:      
		/**
	 * @param tablename
	 * @return 
	 */
	public JSONObject insertDataToP(String tablename,int num) {
		JSONObject obj=new JSONObject();
		
                 String deleteSql="TRUNCATE TABLE "+tablename;
                  
                 Object count = Db.use("sqls").query("select count(1)  from  "+tablename);
                 System.out.println("count "+count);
        
                 List<Record> list =Db.use("sqls").find("select  * from  "+tablename );
                
                 System.out.println(list.size());
        
                 Db.use("post").update(deleteSql);
                 
                 Db.use("post").batchSave(tablename, list, num);
                 
        	 return obj;
		
	}

当我从sqlserver抽出数据list之后放入到postgre数据库中,

解析到的语句是这样的 insert into 'JAN_MST'('JAN_CD','CLA8_CD') values (101,110000001);

报错了,在数据库中把 ‘’去掉    insert into JAN_MST(JAN_CD,CLA8_CD) values (101,110000001);会插入成功。

问题点:这个需要在哪里设置一下解析的格式么?

            还是说多数据源设置问题?

[ERROR] 02 十二月 02:20:26.668 下午 http-bio-9999-exec-2 [cn.tre.api.DBDataAPI]

Class:TemplateAPI Function: updateDeployment Param:

com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.BatchUpdateException: バッチ投入 0 insert into "TB_JAN_MST"("AT_DEL_BAN_FLG", "AT_DIS", "AT_DIS_BAN_FLG", "BARGAIN_KIND", "BARGAIN_PLAN_CD", "CATEGORY1_CD", "CATEGORY2_CD", "CATEGORY3_CD", "CLA8_CD", "COST_PRICE", "COST_PRICE_MARKUP_DIV", "CUSTOM_DGT9_NUMERIC1", "CUSTOM_DGT9_NUMERIC2", "CUSTOM_DGT9_NUMERIC3", "CUSTOM_DGT9_NUMERIC4", "CUSTOM_DGT9_NUMERIC5", "DAILY_PLAN_NO", "DATA_MAKE_FLG", "DEL_FLG", "ELEC_CPN_END_DAY", "ELEC_CPN_GRANT_PNT", "ELEC_CPN_NORMAL_PNT_AMT_FLG", "ELEC_CPN_PLAN_CD", "ELEC_CPN_START_DAY", "ELEC_CPN_TYPE", "ENACT_AMT", "FACT_END_DAY_TIME", "FACT_START_DAY_TIME", "FINAL_SALES_DAY", "FINAL_UPDATE_DAY_TIME", "GROUP_NO", "GUARANTEE_SUBSTIT_ISSUE_DIV", "GUI_CUT_AMT", "HQ_FLG", "JAN_CD", "JAN_NAME", "JAN_NAME_ANK", "JAN_STS1", "JAN_STS10", "JAN_STS11", "JAN_STS12", "JAN_STS13", "JAN_STS14", "JAN_STS15", "JAN_STS16", "JAN_STS17", "JAN_STS18", "JAN_STS19", "JAN_STS2", "JAN_STS20", "JAN_STS21", "JAN_STS22", "JAN_STS23", "JAN_STS24", "JAN_STS25", "JAN_STS26", "JAN_STS27", "JAN_STS28", "JAN_STS29", "JAN_STS3", "JAN_STS30", "JAN_STS31", "JAN_STS32", "JAN_STS33", "JAN_STS34", "JAN_STS35", "JAN_STS36", "JAN_STS37", "JAN_STS38", "JAN_STS39", "JAN_STS4", "JAN_STS40", "JAN_STS41", "JAN_STS42", "JAN_STS43", "JAN_STS44", "JAN_STS45", "JAN_STS46", "JAN_STS47", "JAN_STS48", "JAN_STS49", "JAN_STS5", "JAN_STS50", "JAN_STS6", "JAN_STS7", "JAN_STS8", "JAN_STS9", "K20_MSG_NO", "MAKER_CD", "MAKER_SUGGESTED_LIST_PRICE", "MAM_NO", "MARKUP", "MDOWN_CLEARANCE_FLG", "MEDICINE_MSG_NO", "MST_UPDATE_DAY", "NORMAL_SD_U_PRICE", "NOW_COST_PRICE", "NOW_COST_PRICE_MARKUP_DIV", "NOW_DIS_FLG", "NOW_MARKUP", "NOW_U_PRICE_FACT_SD_U_PRICE", "NPLU_FLG", "ORIGINAL_CD", "PRCS_BARGAIN_PLAN_NO", "PRCS_NO", "PRI_DAILY_PLAN_NO", "PRI_PLAN_NO", "PRI_SALE_LIMIT_UNITS", "SD_U_PRICE_CH_BAN_FLG", "SET_SALE_UNITS", "SPE_MAG", "SPEC_NAME", "STAFF_CD", "START_DAY", "TAXATION_ID", "USER_MNT_FLG2", "VENDOR_CD") values(0, 0, 0, 0, 0, 0, 0, 0, 1090, '0.00', 1, 0, 0, 0, 0, 0, 0, 0, 0, '1900-01-01 00:00:00.000000 +09:00:00', 0, 0, 0, '1900-01-01 00:00:00.000000 +09:00:00', 0, 0, '1900-01-01 00:00:00.000000 +09:00:00', '1900-01-01 00:00:00.000000 +09:00:00', '2016-07-14 13:50:22.000000 +09:00:00', '2016-07-14 13:50:22.000000 +09:00:00', 0, 0, 0, 0, '1', 'テスト1類', '', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '0.00', 0, 1, '2016-07-06 18:10:43.537000 +09:00:00', 1000, '0.00', 1, 0, '0.00', 1000, 0, '1', 0, 0, 0, 0, 0, 0, 0, 10, '', '99999', '2016-07-06 00:00:00.000000 +09:00:00', 2, 0, 0) は停止しました。getNextExceptionを呼んで原因を見て下さい。

at com.jfinal.plugin.activerecord.DbPro.batch(DbPro.java:981)

at com.jfinal.plugin.activerecord.DbPro.batchSave(DbPro.java:1093)

at cn.tre.services.DBService.insertDataToP(DBService.java:45)

at cn.tre.api.DBDataAPI.insertDataToP(DBDataAPI.java:23)

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.jfinal.plugin.activerecord.tx.Tx.intercept(Tx.java:77)

at com.jfinal.aop.Invocation.invoke(Invocation.java:67)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: java.sql.BatchUpdateException: バッチ投入 0 insert into "TB_JAN_MST"("AT_DEL_BAN_FLG", "AT_DIS", "AT_DIS_BAN_FLG", "BARGAIN_KIND", "BARGAIN_PLAN_CD", "CATEGORY1_CD", "CATEGORY2_CD", "CATEGORY3_CD", "CLA8_CD", "COST_PRICE", "COST_PRICE_MARKUP_DIV", "CUSTOM_DGT9_NUMERIC1", "CUSTOM_DGT9_NUMERIC2", "CUSTOM_DGT9_NUMERIC3", "CUSTOM_DGT9_NUMERIC4", "CUSTOM_DGT9_NUMERIC5", "DAILY_PLAN_NO", "DATA_MAKE_FLG", "DEL_FLG", "ELEC_CPN_END_DAY", "ELEC_CPN_GRANT_PNT", "ELEC_CPN_NORMAL_PNT_AMT_FLG", "ELEC_CPN_PLAN_CD", "ELEC_CPN_START_DAY", "ELEC_CPN_TYPE", "ENACT_AMT", "FACT_END_DAY_TIME", "FACT_START_DAY_TIME", "FINAL_SALES_DAY", "FINAL_UPDATE_DAY_TIME", "GROUP_NO", "GUARANTEE_SUBSTIT_ISSUE_DIV", "GUI_CUT_AMT", "HQ_FLG", "JAN_CD", "JAN_NAME", "JAN_NAME_ANK", "JAN_STS1", "JAN_STS10", "JAN_STS11", "JAN_STS12", "JAN_STS13", "JAN_STS14", "JAN_STS15", "JAN_STS16", "JAN_STS17", "JAN_STS18", "JAN_STS19", "JAN_STS2", "JAN_STS20", "JAN_STS21", "JAN_STS22", "JAN_STS23", "JAN_STS24", "JAN_STS25", "JAN_STS26", "JAN_STS27", "JAN_STS28", "JAN_STS29", "JAN_STS3", "JAN_STS30", "JAN_STS31", "JAN_STS32", "JAN_STS33", "JAN_STS34", "JAN_STS35", "JAN_STS36", "JAN_STS37", "JAN_STS38", "JAN_STS39", "JAN_STS4", "JAN_STS40", "JAN_STS41", "JAN_STS42", "JAN_STS43", "JAN_STS44", "JAN_STS45", "JAN_STS46", "JAN_STS47", "JAN_STS48", "JAN_STS49", "JAN_STS5", "JAN_STS50", "JAN_STS6", "JAN_STS7", "JAN_STS8", "JAN_STS9", "K20_MSG_NO", "MAKER_CD", "MAKER_SUGGESTED_LIST_PRICE", "MAM_NO", "MARKUP", "MDOWN_CLEARANCE_FLG", "MEDICINE_MSG_NO", "MST_UPDATE_DAY", "NORMAL_SD_U_PRICE", "NOW_COST_PRICE", "NOW_COST_PRICE_MARKUP_DIV", "NOW_DIS_FLG", "NOW_MARKUP", "NOW_U_PRICE_FACT_SD_U_PRICE", "NPLU_FLG", "ORIGINAL_CD", "PRCS_BARGAIN_PLAN_NO", "PRCS_NO", "PRI_DAILY_PLAN_NO", "PRI_PLAN_NO", "PRI_SALE_LIMIT_UNITS", "SD_U_PRICE_CH_BAN_FLG", "SET_SALE_UNITS", "SPE_MAG", "SPEC_NAME", "STAFF_CD", "START_DAY", "TAXATION_ID", "USER_MNT_FLG2", "VENDOR_CD") values(0, 0, 0, 0, 0, 0, 0, 0, 1090, '0.00', 1, 0, 0, 0, 0, 0, 0, 0, 0, '1900-01-01 00:00:00.000000 +09:00:00', 0, 0, 0, '1900-01-01 00:00:00.000000 +09:00:00', 0, 0, '1900-01-01 00:00:00.000000 +09:00:00', '1900-01-01 00:00:00.000000 +09:00:00', '2016-07-14 13:50:22.000000 +09:00:00', '2016-07-14 13:50:22.000000 +09:00:00', 0, 0, 0, 0, '1', 'テスト1類', '', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '0.00', 0, 1, '2016-07-06 18:10:43.537000 +09:00:00', 1000, '0.00', 1, 0, '0.00', 1000, 0, '1', 0, 0, 0, 0, 0, 0, 0, 10, '', '99999', '2016-07-06 00:00:00.000000 +09:00:00', 2, 0, 0) は停止しました。getNextExceptionを呼んで原因を見て下さい。

at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2762)

at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1999)

at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:421)

at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2929)

at com.alibaba.druid.filter.FilterChainImpl.statement_executeBatch(FilterChainImpl.java:2596)

at com.alibaba.druid.filter.FilterAdapter.statement_executeBatch(FilterAdapter.java:2475)

at com.alibaba.druid.filter.FilterEventAdapter.statement_executeBatch(FilterEventAdapter.java:279)

at com.alibaba.druid.filter.FilterChainImpl.statement_executeBatch(FilterChainImpl.java:2594)

at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.executeBatch(StatementProxyImpl.java:192)

at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeBatch(DruidPooledPreparedStatement.java:559)

at com.jfinal.plugin.activerecord.DbPro.batch(DbPro.java:943)

at com.jfinal.plugin.activerecord.DbPro.batch(DbPro.java:979)

... 28 more


评论区

JFinal

2016-12-02 12:21

多数据源情况,需要为不同数据源设置不同的方言,例如:
dsSqlServer.setDialect(new SqlServerDialect());
pg.setSetDialect(new PostgreSqlDialect());

这样在使用 Db.use(...) 切换到不同的数据源之后, sql 也会被调整

静静滴疯

2016-12-02 12:22

@JFinal 对啊,设置数据源的时候是这么设置的

静静滴疯

2016-12-02 12:24

@JFinal 这样我该怎样解决 sql语句中自动加了 '' 这个问题呢?

JFinal

2016-12-02 12:26

@静静滴疯 看了一下异常,很明显你是将 postgresql 的方言设置成了 mysql 方言

JFinal

2016-12-02 12:27

不是字符 "'" 而是字符 "`",这个字符是键盘数 1 左边的按钮上的字符,这个是 mysql 专用字符,已经证明了你用的是 mysql dialect,需要改成 PostgreSqlDialect

静静滴疯

2016-12-02 12:31

@JFinal 我用的是PostgreSqlDialect 啊,没有配置mysql的项目里面

JFinal

2016-12-02 12:47

@静静滴疯 截图中的字符是 "`" 而不是 "'" ,注意看一下,终级解决方案是单步调试程序,看一下 batchSave() 方法内部用的 Config 对象中的 dialect 到底是什么类型,一目了然

似水流言1

2016-12-02 13:03

ActiveRecordPlugin arp2 = new ActiveRecordPlugin("post",druidPlugin2);
arp.setDialect(new PostgreSqlDialect());
这个地方你方言设置的是arp不是arp2看是不是这个地方设置问题

似水流言1

2016-12-02 13:08

你这个arp2等于没设置方言默认的就是mysql了

静静滴疯

2016-12-02 13:15

@似水流言1 我在修改一下,测试了好久还是不好用

似水流言1

2016-12-02 13:18

现在是报什么错误了啊

静静滴疯

2016-12-02 13:22

@JFinal 现在变成了双引号

JFinal

2016-12-02 13:31

本质就是一个方言设置问题,仔细看下手册

静静滴疯

2016-12-02 13:32

@JFinal 好我再去认真看一遍,回来解决

JFinal

2016-12-02 13:33

@静静滴疯 方言是对应于某个 ActiveRecordPlugin,而 dataSource 也是对应于某个 ActiveRecordPlugin,对应关系需要使用 configName 来做,在创建 ActiveRecordPlugin 时需要为其指定一个 configName

热门反馈

扫码入社