
You can pass/fetch LocalDate objects directly to/from your database via PreparedStatement::setObject and ResultSet::getObject.
#Setdate driver
If using a JDBC driver compliant with JDBC 4.2 or later spec, no need to use the old class. In java.time, the class represents a date-only value without time-of-day and without time zone.
#Setdate android
Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport and further adapted to Android in ThreeTenABP. And search Stack Overflow for many examples and explanations.

The Joda-Time team also advises migration to java.time. These classes supplant the old troublesome date-time classes such as. The java.time framework is built into Java 8 and later. No need to convert if your driver is updated. The Answer by Vargas is good about mentioning java.time types but refers only to converting to. …and… myResultSet.getObject( …, LocalDate.class ) With JDBC 4.2 or later and java 8 or later: tObject( …, myLocalDate ) If you require the current timestamp: ps.setTimestamp(2, new (System.currentTimeMillis())) Suppose you have a variable endDate of type, you make the conversion thus: ps.setTimestamp(2, new (endDate.getTime())) The method () received a string representing a date in the format yyyy-m-d hh:mm:ss. If your table has a column of type TIMESTAMP or DATETIME: If you want to insert the current date: ps.setDate(2, new (System.currentTimeMillis())) Suppose you have a variable endDate of type, you make the conversion thus: ps.setDate(2, new (endDate.getTime()) The method () received a string representing a date in the format yyyy-m-d. Should I use setString() instead with a to_date()? I get this error when the SQL gets executed: Īt .TAFModuleMain.CallTAF(TAFModuleMain.java:1211) Prs.setDate(3,date.valueOf(sqlFollowupDT)) Prs.setDate(2,date.valueOf(vDateMDYSQL)) RequestSQL = "INSERT INTO CREDIT_REQ_TITLE_ORDER (REQUEST_ID," + String vDateMDY = dateFormatMDY.format(now) String vDateYMD = dateFormatYMD.format(now)

Here is the code: DateFormat dateFormatYMD = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss") ĭateFormat dateFormatMDY = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss") I am however facing a problem with the setDate(). In order to make our code more standard, we were asked to change all the places where we hardcoded our SQL variables to prepared statements and bind the variables instead.
