简体   繁体   English

SimpleJdbcInsert与MySQL

[英]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的重点。

  • MySQL version is 5.5.9 MySQL版本是5.5.9
  • MySQL Connector/J 5.1.23 MySQL Connector / J 5.1.23
  • Spring 3.2.1 春天3.2.1

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.

相关问题 MySQL DB 上的 SimpleJdbcInsert 在 executeAndReturnKey 方法后返回 BigInteger 而不是 Long - SimpleJdbcInsert on MySQL DB returning BigInteger instead of Long after executeAndReturnKey method 如何使用SimpleJdbcInsert和executeBatch与MYSQL JDBC驱动程序生成密钥? - How to get generated keys using SimpleJdbcInsert and executeBatch with MYSQL JDBC driver? 如何使用 SimpleJdbcInsert 和 MapSqlParameterSource 批量插入? - How to batch insert with SimpleJdbcInsert and MapSqlParameterSource? 如何修复 SpringBoot 应用程序中 SimpleJdbcInsert 中的错误 - How to fix error in SimpleJdbcInsert in SpringBoot application 使用SimpleJdbcInsert和Sybase检索生成的密钥时出现问题 - Issue retrieving generated keys with SimpleJdbcInsert and Sybase SimpleJdbcInsert-不以默认模式在表中插入数据 - SimpleJdbcInsert - Not inserting data in tables in default schema 由于 null 自动生成的 id (HSQLDB),SimpleJdbcInsert 无法插入 - SimpleJdbcInsert fail to insert because of null autogenerated id (HSQLDB) 是否有一个类似于usingColumns()的SimpleJdbcInsert方法,该方法将排除列列表作为参数? - Is there a SimpleJdbcInsert method similar to usingColumns(), which takes excluded columns list as an argument? Spring 3.2使用SimpleJdbcInsert检索自动生成的密钥 - Spring 3.2 retrieving auto-generated keys using SimpleJdbcInsert Springs SimpleJdbcInsert不会按预期产生自动生成的密钥 - Springs SimpleJdbcInsert doesn't produce auto-generated keys as expected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM