开发者

How to insert TimeStamp with Zone Time in Insert Statement

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜