public final getBy String columnName Object value try Connection con D

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
public final T getBy(String columnName, Object value) {
try (Connection con = Db.getConnection();
PreparedStatement pstmt = con.prepareStatement("SELECT * FROM " + table()
+ " WHERE " + columnName + " = ?" + (multiversion ? " AND latest = TRUE LIMIT 1" : ""))) {
if(value instanceof Long){
pstmt.setLong(1, (Long)value);
}else if(value instanceof Boolean){
pstmt.setBoolean(1, (Boolean)value);
}else if(value instanceof String){
pstmt.setString(1, (String)value);
}
return get(con, pstmt);
} catch (SQLException e) {
throw new RuntimeException(e.toString(), e);
}
}