Announcement Announcement Module
Collapse
No announcement yet.
JDBC : INSERT Data Column Type Error and ClassCast Exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JDBC : INSERT Data Column Type Error and ClassCast Exception

    I am new to Spring and facing issue while insert record to the table using JdbcTemplate

    Database : Oracle

    My table looks like this

    CREATE TABLE AUDIT_LOG (
    AUDITID NUMBER (16) NOT NULL,
    TIMESTAMP DATE,
    RESULT VARCHAR2 (50)
    )

    My code :
    new JdbcTemplate(getDataSource()).
    update(
    "insert into audit_log ("auditid,timestamp, reason) values (?,?,?)",
    new Object[] {id,getDate(),new String("Success Message")} );
    I getting error saying
    "org.springframework.jdbc.UncategorizedSQLExceptio n: (executing PreparedStatementCallback [org.spring
    framework.jdbc.core.JdbcTemplate$SimplePreparedSta tementCreator@18fbefd]): encountered SQLException
    [Invalid column type]; nested exception is java.sql.SQLException: Invalid column type
    java.sql.SQLException: Invalid column type
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBE rror.java:134)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBE rror.java:179)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBE rror.java:269)
    at oracle.jdbc.driver.OraclePreparedStatement.setObje ct(OraclePreparedStatement.java:2886)
    at oracle.jdbc.driver.OraclePreparedStatement.setObje ct(OraclePreparedStatement.java:3015)
    at org.apache.commons.dbcp.DelegatingPreparedStatemen t.setObject(DelegatingPreparedStatement
    .java:165)
    at org.apache.commons.dbcp.DelegatingPreparedStatemen t.setObject(DelegatingPreparedStatement
    .java:165)
    at org.springframework.jdbc.core.JdbcTemplate$ArgPrep aredStatementSetter.setValues(JdbcTempl
    ate.java:730)
    at org.springframework.jdbc.core.JdbcTemplate$5.doInP reparedStatement(JdbcTemplate.java:421)

    at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:292)
    at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:418)
    at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:438)
    at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:446)"

    I understand from this forum that if we provide date object as null, it throws error. so If I have additional parameter for ParameterArgs -

    new JdbcTemplate(getDataSource()).
    update(
    "insert into audit_log ("auditid,timestamp, reason) values (?,?,?)",
    new Object[] {id,getDate(),new String("Success Message")},
    new int[]{Types.INTEGER,Types.DATE, Types.VARCHAR}
    );


    Now i am getting ClassCastException

    java.lang.ClassCastException
    at oracle.jdbc.driver.OraclePreparedStatement.setObje ct(OraclePreparedStatement.java:2832)
    at oracle.jdbc.driver.OraclePreparedStatement.setObje ct(OraclePreparedStatement.java:2905)
    at org.apache.commons.dbcp.DelegatingPreparedStatemen t.setObject(DelegatingPreparedStatement
    .java:162)
    at org.apache.commons.dbcp.DelegatingPreparedStatemen t.setObject(DelegatingPreparedStatement
    .java:162)
    at org.springframework.jdbc.core.JdbcTemplate$ArgType PreparedStatementSetter.setValues(JdbcT
    emplate.java:759)
    at org.springframework.jdbc.core.JdbcTemplate$5.doInP reparedStatement(JdbcTemplate.java:421)

    at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:292)
    at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:418)
    at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:438)
    at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:442)

    Anyone face the same problem..

    Regards,

    Guru

  • #2
    Try using "Types.INTEGER,Types.TIMESTAMP, Types.VARCHAR"

    Comment


    • #3
      Thanks trisberg .. It workss..

      Comment

      Working...
      X