I have my rowmapper like:
private static final class UserRowMapper implements RowMapper<User> {
User user = new User();
user.setId(rs.getInt("id"));
user.setUserType( (UserType)rs.getInt("userType")); // ?????
return user;
}
So I am trying to cast the integer value in the db for userType to the enumeration UserType.
Why doesn't this work?
Cast it? No, can't be done.
You can call valueOf to get the Enum value from the String, as long as the String is valid.
You can index into Enum.values()
:
user.setUserType( UserType.values()[rs.getInt("userType")] );
You might want to put in some error checking. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With