参考:
https://www.cnblogs.com/wangyujun/p/10687780.html
https://www.cnblogs.com/caoyc/p/5630622.html
实例:
insert into SHARK_REGDATA_DEV03.EOD_SNAPSHOT_PSHR (BANK_ID, NAME, RECORD_DATETIME, PSHR_ID, LOCATION) values (?,?,?,?,?)
1 {... 2 3 this.tds3EodSnapshotPSHRheaderList =dataRows.get(0).columnNames(); 4 this.tds3EodSnapshotPSHRbatchArgs = new ArrayList<Object[]>(); 5 for(DataRow row : dataRows){ 6 Object[] batchArgs = new Object[tds3EodSnapshotPSHRheaderList.size()]; 7 int i = 0; 8 for (String column : tds3EodSnapshotPSHRheaderList) { 9 batchArgs[i++] = row.get(column); 10 } 11 this.tds3EodSnapshotPSHRbatchArgs.add(batchArgs); 12 } 13 14 15 dao.insertEodSnapshotPSHR(tds3EodSnapshotPSHRheaderList, tds3EodSnapshotPSHRbatchArgs); 16 17 ... 18 } 19 20 21 22 public int[] insertEodSnapshotPSHR(List<String> headerList, List<Object[]> batchArgs){ 23 String value = "(?"; 24 for(int i=1; i<headerList.size();i++){ 25 value += ",?"; 26 } 27 value += ")"; 28 String sql = String.format("insert into %s.EOD_SNAPSHOT_PSHR (%s) values "+value, schema, headerList.toString().replace("[","").replace("]","")); 29 if (batchArgs.isEmpty()) { 30 return null; 31 } else { 32 return jdbcTemplate.batchUpdate(sql,batchArgs); 33 } 34 }
其中参数如下表举例:
tds3EodSnapshotPSHRheaderList
tds3EodSnapshotPSHRbatchArgs
报错:
原因:
to_timestamp 无法识别为Oracle内置函数
解决方案:
insert into SHARK_REGDATA_DEV03.EOD_SNAPSHOT_PSHR (BANK_ID, NAME, RECORD_DATETIME, PSHR_ID, LOCATION) values (?,?,to_timestamp(?,'YYYY-MM-DD HH24:MI:SS'),?,?)
另一个实例中使用jdbcTemplate.update又遇到ORA-00911: invalid character
https://blog.csdn.net/jiangyu1013/article/details/70237550
原因:
sql结尾处多了一个" ; "