spring-boot - 使用 SimpleJdbcInsert 插入没有 bean 的表中。
问题描述
我的代码:
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'));
有用
解决方案
定义 SimpleJdbcInsert 时,除了表名,还需要指定列:
String[] columns = {"column1","column2"}
SimpleJdbcInsert jdbcInsert = new SimpleJdbcInsert(dataSource)
.usingColumns(columns)
.withTableName(table);
推荐阅读
- c++ - 一直在监听 UDP 服务器
- flutter - 在颤振中使用 agora_rtc_engine 4.0.6 进行视频通话的黑屏
- api-gateway - 大使 API 密钥管理
- javascript - INDEXEDDB 更新/放置未返回预期状态的更新对象
- visual-studio-code - 如何在 Visual Studio 代码中编辑 jupyter 笔记本单元格的标签?
- python - discord.py 命令组中的子命令是否继承父命令的装饰器?
- c++ - 我的代码在标准输入中显示 4(Coreect),在 USACO 分级机中显示 5645,在 scanf/printf 中显示 1862013874。问题是什么?
- python - 我试图制作一个乘法表
- python - 使用 JayDeBeApi 存储 MySQL 二进制文件(16)
- c++ - 如何区分ascii值和数字?