我的代码:
SimpleJdbcInsert jdbcInsert = new SimpleJdbcInsert(dwDatasource).withTableName("DW.MYTABLE1");
Map<String,Object> parameters1 = new HashMap<String,Object>();
parameters1.put("STRING2", "Entry2");
jdbcInsert.execute(parameters1);
我得到:
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Unable to locate columns for table 'MYTABLE1' so an insert statement can't be generated
注意:如果要在jdbctemplate上设置相同的数据源并执行
jdbcTemplate.update("INSERT INTO DW.MYTABLE1 (STRING2) VALUES ('Entry2'));
有效
答案 0 :(得分:0)
定义SimpleJdbcInsert时,除表名外,还需要指定列:
String[] columns = {"column1","column2"}
SimpleJdbcInsert jdbcInsert = new SimpleJdbcInsert(dataSource)
.usingColumns(columns)
.withTableName(table);