Created
May 29, 2018 18:34
-
-
Save mageddo/be0e19441591ddac36287607cd2b5f61 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.sql.Date; | |
| import java.sql.PreparedStatement; | |
| import java.sql.ResultSet; | |
| import java.sql.SQLException; | |
| import java.sql.Timestamp; | |
| import java.sql.Types; | |
| import java.time.LocalDate; | |
| import java.time.LocalDateTime; | |
| import java.util.Optional; | |
| public class JdbcHelper { | |
| public static Integer getInteger(ResultSet rs, String label) throws SQLException { | |
| return rs.getObject(label, Integer.class); | |
| } | |
| public static LocalDateTime getLocalDateTime(ResultSet rs, String label) throws SQLException { | |
| return Optional.ofNullable(rs.getTimestamp(label)) | |
| .map(Timestamp::toLocalDateTime) | |
| .orElse(null); | |
| } | |
| public static LocalDate getLocalDate(ResultSet rs, String label) throws SQLException { | |
| return Optional.ofNullable(rs.getDate(label)) | |
| .map(Date::toLocalDate) | |
| .orElse(null); | |
| } | |
| public static void setInteger(PreparedStatement ps, int offset, Integer value) throws SQLException { | |
| ps.setObject(offset, value, Types.INTEGER); | |
| } | |
| public static void setLong(PreparedStatement ps, int offset, Long value) throws SQLException { | |
| ps.setObject(offset, value, Types.BIGINT); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment