Default JDBC date format when reading date as a string from ResultSet

前端 未结 4 1458
鱼传尺愫
鱼传尺愫 2020-12-17 01:37

I\'m looking at some code that basically does the following:

ResultSet rs = ps.executeQuery();
String myDateStr = rs.getString(\"MY_DATE\"); //field is of ty         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-17 02:37

    Instead of using

    String myDateStr = rs.getString("MY_DATE") 
    

    you should use

    Timestamp timestamp = rs.getTimestamp("MY_DATE");
    

    JDBC / Database will handle the date transformation for you.

提交回复
热议问题