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

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

spring-projects-issues opened this issue Jul 1, 2014 · 2 comments
in: data type: enhancement


Copy link

@spring-projects-issues spring-projects-issues commented Jul 1, 2014

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);


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( ~[ojdbc6.jar:]
   at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal( ~[ojdbc6.jar:]
   at oracle.jdbc.driver.OraclePreparedStatement.setObject( ~[ojdbc6.jar:]
   at oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject( ~[ojdbc6.jar:]
   at org.springframework.jdbc.core.StatementCreatorUtils.setValue( ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal( ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue( ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.setValues( ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement( ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.JdbcTemplate.execute( ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.JdbcTemplate.update( ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.JdbcTemplate.update( ~[spring-jdbc-3.2.8.RELEASE.jar:3.2.8.RELEASE]
   at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update( ~[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/ with same role as CLOB!

Affects: 3.2.9, 4.0.5

Issue Links:

  • #20702 When using NamedParameterJdbcTemplate, NVARCHAR or NCLOB(4000 characters or less) columns are not properly populated since StatementCreatorUtils does setString for these types instead of setNString.
  • #13215 Can't insert into nvarchar2 using SimpleJdbcInsert whereas it works with SimpleJdbcTemplate
  • #16854 INSERT SELECT of large CLOB causes ORA-01461 on setString
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 1, 2014

Juergen Hoeller commented

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


Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 2, 2014

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: data type: enhancement
None yet

No branches or pull requests

2 participants