How to get date datatype from sql database to java?

前端 未结 2 1356
情深已故
情深已故 2020-12-12 05:45

How to get the date datattype from sql database to java??? so far I have use this code but failed to fetch the date.

import java.sql.*;//this is my import          


        
相关标签:
2条回答
  • 2020-12-12 06:13

    You have two options.
    1 - Take sql date object and construct utils date using the getTime method of sql date
    or
    2 - call getTimeStamp instead of getDate , It will return object of sql timeStamp class that is actually child class of java.util.Date

    1 -  Date d1 = new Date(rs.getDate("date_time").getTime());
    2 -  Date d2 = rs.getTimestamp("date_time");
    
    0 讨论(0)
  • 2020-12-12 06:16

    If combo box is not allowing object to inserted, while adding it to the combo_box use d_time.toString() method.

    0 讨论(0)
提交回复
热议问题