我使用pattern =“dd-MMM-yyyy”在JSF中显示日期.
当我尝试将日期值插入/更新到我的oracle DB中时,我得到了
java.sql.sqlException: Invalid column type
因为插入或更新之前的日期格式是这种格式
Wed Feb 09 00:00:00 AST 2011
如何正确地将我的日期值插入或更新到Oracle Db以及执行此操作的最佳方法是什么?
更新1
我的db插入代码.
private void editSchedule(Schedule schedule) Object[] values = { schedule.getStartDate(),schedule.getVacationId() }; Connection connection = null; PreparedStatement preparedStatement = null; try { connection = datacon.getConnection(); preparedStatement = prepareStatement(connection,sql_EDIT,values); preparedStatement.executeUpdate(); } catch (Exception e) { logger.info("errro "+e.getMessage()); e.printStackTrace(); } finally { // TODO: handle exception close(connection,preparedStatement); } }
PreparedStaement代码部分
public static PreparedStatement prepareStatement (Connection connection,String sql,Object... values) throws sqlException { PreparedStatement preparedStatement = connection.prepareStatement(sql ); setValues(preparedStatement,values); return preparedStatement; } public static void setValues(PreparedStatement preparedStatement,Object... values) throws sqlException { for (int i = 0; i < values.length; i++) { preparedStatement.setObject(i + 1,values[i]); logger.info("sql "+Arrays.asList(values)); } }