476
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
How It Works
In Java 8, the new Date-Time API (Chapter
4
) is the preferred API for working with dates
and times. Therefore, when working
with date values and databases, the JDBC API must
convert between SQL dates and new Date-Time LocalDate objects.
The solution to this
recipe demonstrates that to obtain an instance of java.sql.Date from a LocalDate
object, you simply invoke the static java.sql.Date.valueOf() method,
passing the
pertinent LocalDate object.
12-13. Closing Resources Automatically
Do'stlaringiz bilan baham: