티스토리 뷰

jdbc를 사용해서 오라클 db에서 데이터를 읽어서 다시 오라클 db로 데이터를 넣을려고 했다.


그냥 아무 생각없이 rs.getString()을 했더니


java.sql.SQDataException: ORA-01861: 리터럴이 형식 문자열과 일치하지 않음


이라고 떳다.


알고 봤더니 날짜형식을 getString으로 받을려고 하니 난 오류였다.


그래서 rs.getDate()로 했더니 오류 없이 진행은 됐는데


날짜형식의 데이터를 보니 년월일 만 있고 시분초가 없었다.


그래서 rs.getTimestamp, rs.setTimestamp로 바꿨더니 되었다!!


======================================================


jdbc에서 resultSet.getDate() 하면 new java.util.Date();

 - 시간, 분, 초 정보는 가지고 있지 않다.


ResultSet 의 메소드를 살펴 보면.


java.sql.ResultSet



public abstract Date getDate(String columnName) throws SQLException

 Get the value of a column in the current row as a java.sql.Date object. 

 Returns: the column value; if the value is SQL NULL, the result is null 



public abstract Time getTime(String columnName) throws SQLException

 Get the value of a column in the current row as a java.sql.Time object. 

 Returns: the column value; if the value is SQL NULL, the result is null 


getDate() 나 getTime() 은 java.util.Date 객체를 반환하는 것이 아니라

java.sql 패키지의 java.sql.Date와 java.sql.Time 객체를 반환하고 있습니다.



반면


public abstract Timestamp getTimestamp(String columnName) throws SQLException

 Get the value of a column in the current row as a java.sql.Timestamp object. 

 Returns: the column value; if the value is SQL NULL, the result is null 



getTimestamp() 는 "java.sql.Date, java.sql.Time, java.sql.Timestamp 는 java.util.Date를 상속받아서

모든 정보를 가지고 있다.




2009.10.21 00:00:00  <-- rs.getDate()

1970.01.01 01:15:38  <-- rs.getTime()

2009.10.21 01:15:38  <-- rs.getTimestamp()



출처: http://childeye.tistory.com/entry/oracle-에서-jdbc로-년월일-시분초-읽어오기 [행복한 스마일맨 ^^*]

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함