简体   繁体   中英

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:

WARN [org.springframework.jdbc.core.metadata.TableMetaDataProvider:locateTableAndProcessMetaData:336] (main:) Unable to locate table meta data for 'tableName' -- column names must be provided

Why does this happen? I know I can manually specify column names, but it's not the point of using JdbcSimpleInsert, I believe.

  • MySQL version is 5.5.9
  • MySQL Connector/J 5.1.23
  • Spring 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 .
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.

I got an identical error, for a different reason. In my JDBC connection string, I listed the schema. Therefore, putting the withSchemaName clause caused this error. When I removed it, the insert worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM