尝试使用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
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
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
}
}