JavaEar 专注于收集分享传播有价值的技术资料

getDateTime doesn't exist - what to use instead?

I have this problem that I have used DateTime from Joda and when I try to getDateTime it of course won't work because ResultSet doesn't have the method. What should I use instead?

I asked a similar question yesterday where I tried to setDateTime and that worked fine but this time I am not sure what to do. I could use getTimeStamp but then I have to change my data according to and that's not appropriate I think. Is there a good workaround here? I much appreciate your help.

while (rs.next()) {
    Contingent c = new Contingent(rs.getInt("contingent_id"),
        rs.getDateTime(("contingent_start_Date"),
        rs.getDateTime("contingent_end_date"),
        rs.getInt("member_id"));

    contingentInfo.add(c);
}

2个回答

    最佳答案
  1. Use getTimestamp(), then convert it to a DateTime.

    DateTime readTheJavadoc = new DateTime(rs.getTimestamp(1));
    
  2. 参考答案2
  3. Following statement should be working:

    DateTime dt = new DateTime( rs.getTimeStamp( your_column_index ).getTime() );
    

    and alternatively

    DateTime dt = new DateTime( rs.getDate( your_column_index ).getTime() );
    

    Refer to:
    DateTime( long instant )

    In reference to Kayaman's comment, there exist other Constructors in the JodaTime's DateTime API, that take an input representing a Date or timestamp.

    Please also Refer to:
    Joda Time: org.joda.time.DateTime Constructors Summary