使用RowMapper从数据库获取日期时出错

时间:2014-02-04 20:45:34

标签: java mysql spring jdbc mapping

当我尝试恢复日期表单数据库时,我收到错误。如果我评论该线它工作正常。有什么想法吗?

数据库中的日期值为00000-00-00 00:00:00,连接良好。

public List<Task> getTasks() {
    return jdbc.query("select * from t_task", new RowMapper<Task>() {

        public Task mapRow(ResultSet rs, int rowNum) throws SQLException {
            Task task = new Task();

            task.setId(rs.getLong("idTask"));
            task.setDate(rs.getDate("date")); //Error here

            return task;
        }

    });
}

它返回此错误:

Exception in thread "main" org.springframework.dao.TransientDataAccessResourceException: StatementCallback; SQL [select * from t_task]; Value '9oneoned00000-00-00 00:00:00�11111�2014-02-04 21:13:31
    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:106)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:407)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:456)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:464)
    at com.javalabs.web.model.TaskDao.getTasks(TaskDao.java:25)
    at com.javalabs.web.test.App.main(App.java:24)

t_task

CREATE TABLE IF NOT EXISTS `myTask`.`t_task` (
  `idTask` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `task` VARCHAR(100) NOT NULL,
  `description` LONGTEXT NOT NULL,
  `pending` TINYINT(1) NOT NULL DEFAULT 0,
  `date` DATETIME NOT NULL,
  `deadline` DATETIME NULL DEFAULT NULL,
  `idTaskCategory` INT(11) UNSIGNED NOT NULL,
  `idTaskPriority` INT(11) UNSIGNED NOT NULL DEFAULT '1',
  `idTaskState` INT(11) UNSIGNED NULL DEFAULT '1',
  `idUser` INT(10) NOT NULL,
  `idUser_responsible` INT(10) NULL DEFAULT NULL,
  `evaluation` LONGTEXT NULL DEFAULT NULL,
  `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)

0 个答案:

没有答案