Skip to content

Support for Types.NCLOB in SqlLobValue to simplify use with NamedParameterJdbcTemplate. [SPR-11938] #16555

Closed

Description

@spring-projects-issues

Oleksandr Gavenko opened SPR-11938 and commented

The only way to avoid LobHandler in DAO code for insert/update:

MapSqlParameterSource paramSource = new MapSqlParameterSource();
paramSource.addValue("clob", "a long long text", Types.CLOB);
namedTemplate.update(INSERT_STMT, paramSource);

See:

another way (only for JdbcTemplate, not for NamedParameterJdbcTemplate):

java.sql.Types has NCLOB constans for Java 6/7/8:

If I do:

paramSource.addValue("clob", "a long long text", Types.CLOB);

all work fine, but with:

paramSource.addValue("clob", "a long long text", Types.NCLOB);

I get:

=> Fail to add incidentjava.lang.ClassCastException: java.lang.String cannot be cast to oracle.sql.CLOB
   at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:8762) ~[ojdbc6.jar:11.2.0.3.0]
   at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8286) ~[ojdbc6.jar:11.2.0.3.0]
   at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:8868) ~[ojdbc6.jar:11.2.0.3.0]
   at oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:240) ~[ojdbc6.jar:11.2.0.3.0]
   at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:406) ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:234) ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:149) ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.setValues(PreparedStatementCreatorFactory.java:298) ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:251) ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:583) ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:818) ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:840) ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:281) ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]

Actual type of table column is NCLOB, and with Type.CLOB code work fine.

My suggestion just add NCLOB to src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java with same role as CLOB!


Affects: 3.2.9, 4.0.5

Issue Links:

Activity

  1. spring-projects-issues commented on Jul 1, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Good point! StatementCreatorUtils populates NVARCHAR, LONGNVARCHAR, NCLOB via setString as well now.

    Juergen

  2. spring-projects-issues commented on Jul 2, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Oleksandr Gavenko commented

    Hi! I apply your changes on top of 3.x series:

    git diff  ec4e6e0^! >.diff
    git reset --hard origin/3.2.x 
    patch -p1 <.diff
    gradle
    

    and test my application with Type.NCLOB. All fine, thanks!

  3. added
    in: data
    type: enhancement
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: datatype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions