How can I convert sql time to java time for an object?

Johnny Van

When i run this code it says this:

Error:(43, 31) java: incompatible types: java.sql.Time cannot be converted to java.time.LocalTime

public TrackTime read(int id){

        rs = jdbc.queryForRowSet("SELECT * FROM tracktime where id ='" + id + "'");
        while (rs.next()){
            return new TrackTime (rs.getInt("id"),
                    rs.getDate("date"),
                    rs.getTime("startTime"),
                    rs.getTime("endTime"),
                    rs.getString("licenseType"),
                    rs.getInt("trackNumber"));
        }

        return new TrackTime();
    }

what can be the cause of this error?

Pushpesh Kumar Rajwanshi

Your constructor for TrackTime class must be expecting object of class LocalTime where as rs.getTime("startTime") returns java.sql.Time instead of LocalTime and as both are not same hence you get the error.

You can use toLocalTime() method on Time object which returns LocalTime object and this way correct object type would get passed to your constructor and should get away from the error.

So in your code you need to do this,

while (rs.next()){
    return new TrackTime (rs.getInt("id"),
            rs.getDate("date"),
            rs.getTime("startTime").toLocalTime(),
            rs.getTime("endTime").toLocalTime(),
            rs.getString("licenseType"),
            rs.getInt("trackNumber"));
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I convert a time in milliseconds to ZonedDateTime

How can I convert YMD LDAP timestamps to date time in Java?

How can I convert 24 hour time to 12 hour time?

How can I convert a datetime object to milliseconds since epoch (unix time) in Python?

How do I convert a Joda Time DateTime object into a String in SQL Server format?

How can I set the System Time in Java?

How can I convert from Gregorian Calendar to Unix Time, in Java?

How to convert string into Time object in Java?

Java: How can I create a TimeZone object for Mountain time?

How do I combine a java.util.Date object with a java.sql.Time object?

How can I convert epoch time to date and time in Java?

how to convert integer time to time object in python

How can I convert the format of time in the dataframe?

How can I format time to a dayjs object?

How do I convert a string into a Time object?

How can I convert UTC time to device's local time?

How can I convert date time from time zone A to time zone B in Joda time?

How can I display one object at a time?

How to convert unformatted time to a python time object

How can i convert this time (GMT Format) to IST Time?

How can I convert timstamp to a readable time?

How can I change the month of a time object?

How I can convert publishedAt to date and time

How can I convert time (time zone)

How can I convert from UTC time to local time in python?

How can I convert Zulu time zone string into specific datetime object?

How can i convert just a time to utc time in c#?

How can I convert a sparse matrix to a time series object?

How can i convert time to unix timestamp?

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive