JDBC JDBC Date 포맷 변환

황제낙엽 2003.11.08 18:10 조회 수 : 739 추천:211

sitelink1  
sitelink2  
sitelink3  
sitelink4  
sitelink5  
sitelink6  
Example>>

/* Source **************************************************************************/
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd a HH:mm:ss");
String result  = sdf.format(new java.util.Date(System.currentTimeMillis()));
System.out.println(result);
/*********************************************************************************/

/* SQL Query **************************************************************************/
select input_time from db_monitor where to_char(input_time , 'RRRR-MM-DD HH24:MI:SS') < '2003-11-08 17:52:35';
/*********************************************************************************/

/* JAVA Code **************************************************************************/
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String input_time  = sdf.format(new java.util.Date(System.currentTimeMillis()));

String QUERY = INSERT INTO 테이블이름 values ( to_date( '"+ input_time +"' , 'RRRR-MM-DD HH24:MI:SS' ) );
/*********************************************************************************/

<참고>
1. 자바서비스넷 이원영씨의 관련 게시글 -> 보기

2. java.sql.Date 클래스에 다음같은 메서드도 있다.

[ public static Date valueOf(String s)
  -> Converts a string in JDBC date escape format to a Date value.

Parameters:
s - a String object representing a date in in the format "yyyy-mm-dd"
Returns:
a java.sql.Date object representing the given date
Throws:
IllegalArgumentException - if the date given is not in the JDBC date escape format (yyyy-mm-dd) ]

3. java.text.SimpleDateFormat 클래스는 java.text.DateFormat 클래스에서 상속받은 다음의 메서드도 있다.

[ public Date parse(String source) throws ParseExceptionParses

-> text from the beginning of the given string to produce a date. The method may not use the entire text of the given string.
See the parse(String, ParsePosition) method for more information on date parsing.

Parameters:
source - A String whose beginning should be parsed.
Returns:
A Date parsed from the string.
Throws:
ParseException - if the beginning of the specified string cannot be parsed. ]