jdbctemplate oracle date類型操做

create table mydate(java

    id int,spring

    seqdate datesql

)this


insert into mydate values(1, to_date('21-08-2003 20:28:03','DD-MM-YYYY HH24:MI:SS'));code

insert into mydate values(2, to_date('22-08-2003 20:28:03','DD-MM-YYYY HH24:MI:SS'));get

insert into mydate values(3, to_date('23-08-2003 20:28:03','DD-MM-YYYY HH24:MI:SS'));it

insert into mydate values(4, to_date('24-08-2003 20:28:03','DD-MM-YYYY HH24:MI:SS'));io

commit;table


select id,to_char(seqdate, 'DD-MM-YYYY HH24:MI:SS') seqdate from mydateclass


spring-jdbctemplate-date:

public Date queryForDate(String sql, Object... args) {
		try {
			Date result = this.getJdbcTemplate().queryForObject(sql, args, Date.class);
			return result;
		} catch (EmptyResultDataAccessException e) {
			return null;
		}
	}
	
public Date getDate(int id) {
		String sql = "select seqdate from mydate where id = ?";
		return jdbctemplate.queryForDate(sql, new Object[] { id });
	}
相關文章
相關標籤/搜索