I am using Micrososft SQL Server 2000 and Sql Server JDBC driver 2005 for data access. When am inserting a null value using SimpleJDBCInsert I get NullPointerException from JDBC Driver. I think there is some problem either in the driver or Spring Code. Somewhere the "setNull" function call is not working properly.
It works fine if I use JDBCTemplate function update(sql, qry, sqlTypes) function call.
It also does not work with SimpleJDBCTemplate. Here is the Stack Trace:
java.lang.NullPointerException
at com.microsoft.sqlserver.jdbc.AppDTVImpl$SetValueOp .executeDefault(Unknown Source)
at com.microsoft.sqlserver.jdbc.DTV.executeOp(Unknown Source)
at com.microsoft.sqlserver.jdbc.AppDTVImpl.setValue(U nknown Source)
at com.microsoft.sqlserver.jdbc.DTV.setValue(Unknown Source)
at com.microsoft.sqlserver.jdbc.Parameter.setValue(Un known Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStat ement.setObject(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStat ement.setNull(Unknown Source)
at org.springframework.jdbc.core.StatementCreatorUtil s.setParameterValueInternal(StatementCreatorUtils. java:152)
at org.springframework.jdbc.core.StatementCreatorUtil s.setParameterValue(StatementCreatorUtils.java:88)
at org.springframework.jdbc.core.ArgPreparedStatement Setter.setValues(ArgPreparedStatementSetter.java:5 1)
at org.springframework.jdbc.core.JdbcTemplate$2.doInP reparedStatement(JdbcTemplate.java:771)
at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:566)
at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:767)
at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:825)
at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:833)
at org.springframework.jdbc.core.simple.AbstractJdbcI nsert.executeInsertInternal(AbstractJdbcInsert.jav a:341)
at org.springframework.jdbc.core.simple.AbstractJdbcI nsert.doExecute(AbstractJdbcInsert.java:331)
at org.springframework.jdbc.core.simple.SimpleJdbcIns ert.execute(SimpleJdbcInsert.java:102)
CCDaoImpl.create(CCDaoImpl.java:77)
Here is the code am using:
Any guidance is appreciated.Code:in the Init method: public void init(DataSource dataSource) { this.insertCC = new SimpleJdbcInsert(dataSource) .withTableName("TABLE1") .usingColumns("COL1", "COL2", "COL3", "COL4"); } In the create method: public void create(CC cc){ SqlParameterSource parameters = new BeanPropertySqlParameterSource(cc); this.insertCC.execute(parameters); } Here If any of COL value is null, it does not work.


Reply With Quote