[英]SimpleJdbcInsert with MySQL
This is the relevan code I wrote: 这是我写的相关代码:
new SimpleJdbcInsert(dataSource)
.withSchemaName("test")
.withTableName("tableName")
.usingGeneratedKeyColumns("idColumn");
When I call the executeAndReturnKey(parameters)
I read this on the console: 当我调用
executeAndReturnKey(parameters)
我在控制台上读到了这个:
WARN [org.springframework.jdbc.core.metadata.TableMetaDataProvider:locateTableAndProcessMetaData:336] (main:) Unable to locate table meta data for 'tableName' -- column names must be provided
WARN [org.springframework.jdbc.core.metadata.TableMetaDataProvider:locateTableAndProcessMetaData:336](main :)无法找到'tableName'的表元数据 - 必须提供列名
Why does this happen? 为什么会这样? I know I can manually specify column names, but it's not the point of using JdbcSimpleInsert, I believe.
我知道我可以手动指定列名,但我相信它不是使用JdbcSimpleInsert的重点。
While executing the same query on a different MySQL server, I've came across this error: java.sql.SQLException: Parameter metadata not available for the given statement
. 在不同的MySQL服务器上执行相同的查询时,我遇到了这个错误:
java.sql.SQLException: Parameter metadata not available for the given statement
。
So I've killed to birds with a stone :) 所以我用石头杀了鸟儿:)
So, just add generateSimpleParameterMetadata=true
to the JDBC connection URL and everything will work as expected. 因此,只需将
generateSimpleParameterMetadata=true
添加到JDBC连接URL ,一切都将按预期工作。
I got an identical error, for a different reason. 出于不同的原因,我得到了相同的错误。 In my JDBC connection string, I listed the schema.
在我的JDBC连接字符串中,我列出了架构。 Therefore, putting the
withSchemaName
clause caused this error. 因此,使用
withSchemaName
子句会导致此错误。 When I removed it, the insert worked. 当我删除它时,插入工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.