Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with SimpleJdbcTemplate#update with null values in Derby [SPR-4809] #9485

Closed
spring-projects-issues opened this issue May 13, 2008 · 1 comment

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented May 13, 2008

Joern Huxhorn opened SPR-4809 and commented

This problem is most likely similar to http://jira.springframework.org/browse/SPR-4465

The table in the DB looks like this:
CREATE TABLE PERSONS (
id BIGINT PRIMARY KEY,
BIRTHDAY BIGINT NOT NULL,

FIRST_NAME VARCHAR(255) NOT NULL,
MIDDLE_NAME VARCHAR(255),
LAST_NAME VARCHAR(255) NOT NULL,
NICK_NAME VARCHAR(255)

)

Executing simpleJdbcTemplate with null for MIDDLE_NAME or NICK_NAME results in an exception.

String sql = "insert into PERSONS (ID, BIRTHDAY, FIRST_NAME, MIDDLE_NAME, LAST_NAME, NICK_NAME) values (?, ?, ?, ?, ?, ?)";
simpleJdbcTemplate.update(sql,
newId,
person.getBirthDay().getTime(),
name.getFirstName(),
name.getMiddleName(),
name.getLastName(),
name.getNickName()
);

org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [insert into PERSONS (ID, BIRTHDAY, FIRST_NAME, MIDDLE_NAME, LAST_NAME, NICK_NAME) values (?, ?, ?, ?, ?, ?)]; An attempt was made to get a data value of type 'VARCHAR' from a data value of type 'null'.; nested exception is java.sql.SQLDataException: An attempt was made to get a data value of type 'VARCHAR' from a data value of type 'null'.
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.translate(SQLExceptionSubclassTranslator.java:63)
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:237)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:607)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:792)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:850)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:858)
at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.update(SimpleJdbcTemplate.java:237)


Affects: 2.5.4

Issue Links:

  • #5936 DB error when setting SqlTypeValue.TYPE_UNKNOWN to null
  • #9142 Problem with SimpleJdbcTemplate#update with null values in DB2
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 21, 2008

Thomas Risberg commented

Assuming this is using the embedded driver. Client driver worked fine with the sample code. For the embedded driver this is solved by using setNull with a type of Types.VARCHAR. Works regardless of the actual column type. Same strategy that we use for DB2 and some Sybase and MS SQL Server drivers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant