lundi 13 juin 2016

Calendar object storage: from Java to MySQL databaseResultSet.getDate(columnLabel, cal)

I have a question regarding the ResultSet.getDate(columnLabel, cal)-method.

This is my code in a class that implements RowMapper:

public Time mapRow( ResultSet rs, int rowNum ) throws SQLException {
       Time time = new Time();
       time.setDates( rs.getDate("modelFrom", calendar), rs.getDate("modelTo", calendar) );
       time.setPosition( rs.getDouble("latitude"), rs.getDouble("longitude"), rs.getInt("altitude") );

       return time;
}

And this is my setDates method in the Time-class:

public void setDates( Calendar modelFrom, Calendar modelTo ) {      
    this.modelFrom = modelFrom;
    this.modelTo = modelTo;
}

So what I'm wondering is how to properly store java Calendar-objectvalues in a MySQL database in my Time-table? Should my Time-table store these as TIMESTAMP or DATETIME?

modelFrom and modelTo are parsed from a XML-document and look like this:

2016-05-19T09:00:00Z

2016-05-29T00:00:00Z

What kind of value should calendar have in the getDate-method?

Aucun commentaire:

Enregistrer un commentaire