开发者

How to insert TimeStamp with Zone Time in Insert Statement

开发者 https://www.devze.com 2023-02-18 18:09 出处:网络
How to insert TimeStamp with Zone Time in Insert Statement... Am getting this as String 2011-03-22T13:33:54+0530

How to insert TimeStamp with Zone Time in Insert Statement... Am getting this as String 2011-03-22T13:33:54+0530 using f开发者_如何学Pythonollowing to convert it to time and insert

String timStp = 2011-03-22T13:33:54+0530
java.sql.Timestamp tsmp = new java.sql.Timestamp(sdf.parse(timStp).getTime()); 
java.sql.Timestamp tsmp11 = new java.sql.Timestamp(sdf.parse(timStp).getTimezoneOffset());

INSERT INTO PUNCHOUT_USER_LOGIN(REQ_TIME) VALUES(TIMESTAMP '"+tsmp+"');

Above query inserted :--> 22-MAR-11 01.12.44.000000000 PM (With out Time Zone )


Do not convert Timestamp to String. Insert it as Timestamp. You can use PreparedStatement#setTimestamp() for this.

String sql = "INSERT INTO PUNCHOUT_USER_LOGIN(REQ_TIME) VALUES(?)";
// ...

try {
    // ...
    preparedStatement = connection.prepareStatement(sql);
    preparedStatement.setTimestamp(1, timestamp);
    // ...
} finally {
    // ...
}

See also:

  • Using prepared statements
0

精彩评论

暂无评论...
验证码 换一张
取 消