Java SQL ResultSet Read getEnumFromResultSet(ResultSet rset, Enum field, T[] enumValues)

Here you can find the source of getEnumFromResultSet(ResultSet rset, Enum field, T[] enumValues)

Description

get Enum From Result Set

License

Open Source License

Declaration

public static <T extends Enum> T getEnumFromResultSet(ResultSet rset, Enum field, T[] enumValues)
            throws SQLException 

Method Source Code

//package com.java2s;
/**/*  w ww  .  j  a  v a  2  s. c  o  m*/
 Copyright (c) 2013, Amit Lieberman
All rights reserved.
    
           GNU LESSER GENERAL PUBLIC LICENSE
               Version 3, 29 June 2007
    
 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.
    
    
  This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License
    
 * Created with love
 * User: shpandrak
 * Date: 10/20/12
 * Time: 10:37
 */

import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {
    public static <T extends Enum> T getEnumFromResultSet(ResultSet rset, Enum field, T[] enumValues)
            throws SQLException {
        return getEnumFromResultSet(rset, field.name(), enumValues);
    }

    public static <T extends Enum> T getEnumFromResultSet(ResultSet rset, String field, T[] enumValues)
            throws SQLException {
        int enumOrdinal = rset.getInt(field);
        return rset.wasNull() ? null : enumValues[enumOrdinal];
    }

    public static <T extends Enum> T getEnumFromResultSet(ResultSet rset, int field, T[] enumValues)
            throws SQLException {
        int enumOrdinal = rset.getInt(field);
        return rset.wasNull() ? null : enumValues[enumOrdinal];
    }
}

Related

  1. getDuplicacy(ResultSet rs)
  2. getEntityMap(ResultSet rs, ResultSetMetaData rsmd)
  3. getEnum(Class enumClass, ResultSet rs, String columnName)
  4. getEnum(ResultSet r, String columnName, Class enumType)
  5. getEnum(ResultSet rs, int index, Class type)
  6. getExpectedType(ResultSet resultSet, int columnIndex)
  7. getExplainPlan(ResultSet rs)
  8. getFieldNames(ResultSet rs)
  9. getFieldsPresentInResultSet(ResultSet rs)