Java SQL ResultSet Read getOptionalInt(ResultSet rs, String name)

Here you can find the source of getOptionalInt(ResultSet rs, String name)

Description

get Optional Int

License

Apache License

Declaration

public static OptionalInt getOptionalInt(ResultSet rs, String name) throws SQLException 

Method Source Code

//package com.java2s;
/*/*from  w w  w.  ja  va  2 s .  c om*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

import java.util.OptionalInt;

public class Main {
    public static OptionalInt getOptionalInt(ResultSet rs, String name) throws SQLException {
        int value = rs.getInt(name);
        return rs.wasNull() ? OptionalInt.empty() : OptionalInt.of(value);
    }
}

Related

  1. getObject(ResultSet resultSet, int columnCount, Map columnLabelMap, String[] fields, String[] columnLabel, Class cls, Boolean flag)
  2. getObject(ResultSet rs, int columnIndex, Class type)
  3. getObject(ResultSet set, int columnIndex)
  4. getObjectByTypeCoercion(ResultSet resultSet, int index, int dataType)
  5. getOjbClassName(ResultSet rs)
  6. getPath(ResultSet r, String columnName)
  7. getRecordsFromResultSet(ResultSet rs)
  8. getResult(ResultSet rs)
  9. getResultArray(ResultSet resultSet, int size, java.util.Date startDate)