Skip to content

SimpleJdbcInsert does not quote table and column names [SPR-9236] #13874

@spring-projects-issues

Description

@spring-projects-issues

Michel Zanini opened SPR-9236 and commented

If you have table or column names that are reserved SQL words, like "varchar", "values", "integer", etc... the generated insert SQL must have escaping.

For example, now SimpleJdbcInsert is generating this SQL:

INSERT INTO crud (text, integer, char, datetime, decimal, varchar) VALUES(?, ?, ?, ?, ?, ?)

but it should be generating this:

INSERT INTO `crud` (`text`, `integer`, `char`, `datetime`, `decimal`, `varchar`) VALUES(?, ?, ?, ?, ?, ?)

As a workaround I am able to make it work adding the escape char "`" to the column names like this:

simpleJdbcInsert.withTableName("`" + tableName + "`");
simpleJdbcInsert.usingColumns("`" + column1 + "`", "`" + column2 + "`", "`" + column3 + "`");

but I believe SimpleJdbcInsert should support this out of the box. For example, it could have a boolean property like this:

simpleJdbcInsert.withTableName(tableName);
simpleJdbcInsert.usingColumns(column1, column2, column3);
simpleJdbcInsert.usingEscaping(true);

and then SimpleJdbcInsert would do the escaping for me.


Affects: 3.1.1

4 votes, 6 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: dataIssues in data modules (jdbc, orm, oxm, tx)status: supersededAn issue that has been superseded by anothertype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions