sql错误:使用Spring JdbcTemplate预处理语句请求的转换无效

时间:2013-12-04 01:07:37

标签: spring jdbctemplate

尝试使用spring 3.0.5 JdbcTemplate API在RECORDERS(oracle 11g)表中插入行时,收到以下“请求的转换无效”错误。

非常感谢任何帮助。

错误

2013-12-03 19:14:40,125,ERROR,,,http-bio-8080-exec-3,RecorderController,Caught exception: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [INSERT INTO RECORDERS(RECORDER_ID,RECORDER_NAME,RECORDER_TYPE,RECORDER_IP,RECORDER_URL,ACTIVE_IND)VALUES(?,?,?,?,?,?)]; SQL state [99999]; error code [17132]; Invalid conversion requested; nested exception is java.sql.SQLException: Invalid conversion requested

这是我们的RECORDERS表结构

Column          Length  Type        Nullable    Primary Key
RECORDER_ID     3       NUMBER      N           1   
RECORDER_NAME   20      VARCHAR2    N                           
RECORDER_TYPE   1       CHAR(1)     N                           
RECORDER_IP     20      VARCHAR2    N       
RECORDER_URL    100     VARCHAR2    N       
ACTIVE_IND      1       CHAR(1)     N   

DAO代码:

public class RecorderDAOImpl {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    private static String INSERT_SQL="INSERT INTO RSDVR_RECORDERS"
            + "(RECORDER_ID,RECORDER_NAME,RECORDER_TYPE,RECORDER_IP,RECORDER_URL,"
            + "ACTIVE_IND)VALUES(?,?,?,?,?,?)";

    public void register(Recorder recorder) throws DataAccessException{
        int nextRowNum = this.getNextRowNum();
        char activeInd =this.getActiveIndicator(recorder.getState());
        Object[] objArr = new Object[] {nextRowNum,recorder.getName(),recorder.getType().charAt(0),
                                        recorder.getIP(),recorder.getURL(),activeInd};
        int[] objTypes = new int[]{Types.INTEGER,Types.VARCHAR,Types.CHAR,
                                    Types.VARCHAR,Types.VARCHAR,Types.CHAR};

        this.jdbcTemplate.update(INSERT_SQL, objArr,objTypes);
    }

    private char getActiveIndicator(final String state){
        LOGGER.info("Enter " + this.getClass().getName() + ".getActiveIndicator()");
        return ("Online".equalsIgnoreCase(state)) ? 'Y': 'N';
    }

    private int getNextRowNum() throws DataAccessException{
        //return next row number
    }

}

0 个答案:

没有答案