Search code examples
sqldatetimegroovygetter-setter

How to read a TimeStamp datetime2(2) from a Sql database into Groovy


I am trying to read a TimeStamp datetime2(2) from a SQL server database which is in the format '2017-05-05 07:00:15.04'. I get a formatting error in my groovy while executing.

i Have used as follows:

private DateTime Time_TimeStamp;

....
// getter and setters///

public DateTime getTime_TimeStamp() {
        return Time_TimeStamp;
    }
    public void setTime_TimeStamp(DateTime time_TimeStamp) {
        Time_TimeStamp = time_TimeStamp;

The error i receive is : FL_DPG_TimeAD.setTime_TimeStamp() is applicable for argument types: (java.sql.Timestamp) values: [2017-05-05 07:00:15.04] Possible solutions: setTime_TimeStamp(long), getTime_TimeStamp()

How can i use exact datetime2(2) which is in format in groovy ?


Solution

  • the error

    FL_DPG_TimeAD.setTime_TimeStamp() is applicable for argument types: (java.sql.Timestamp) values: [2017-05-05 07:00:15.04]

    Possible solutions: setTime_TimeStamp(long), getTime_TimeStamp()

    means that the method setTime_TimeStamp in your object FL_DPG_TimeAD accepts long but you try to pass into this method java.sql.Timestamp

    you just have to find a way to convert Timestamp to long

    check the documentation for java.sql.Timestamp

    there is a method getTime() that returns timestamp as a long value