Here you can find the source of readBitBoolean(ResultSet result, int index)
Parameter | Description |
---|---|
results | The result set. |
index | The index. |
Parameter | Description |
---|---|
SQLException | an exception |
public static Boolean readBitBoolean(ResultSet result, int index) throws SQLException
//package com.java2s; /********************************************************************************** * $URL$//from ww w .j av a 2 s . c o m * $Id$ *********************************************************************************** * * Copyright (c) 2007, 2008 The Regents of the University of Michigan & Foothill College, ETUDES Project * * 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.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; public class Main { /** * Read a Boolean (encoded in a bit or tinyint or string field or whatever) from the results set. * * @param results * The result set. * @param index * The index. * @return The Boolean. * @throws SQLException */ public static Boolean readBitBoolean(ResultSet result, int index) throws SQLException { Object o = result.getObject(index); if (o == null) return null; Boolean rv = null; if (o instanceof Boolean) { rv = (Boolean) o; } else if (o instanceof Integer) { rv = Boolean.valueOf(((Integer) o).intValue() == 1); } else if (o instanceof BigDecimal) { rv = Boolean.valueOf(((BigDecimal) o).intValue() == 1); } else if (o instanceof String) { if (((String) o).length() > 0) { String s = (String) o; if (s.equals("1") || s.equals("0")) { rv = Boolean.valueOf(s.equals("1")); } else if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false")) { rv = Boolean.valueOf(s.equalsIgnoreCase("true")); } else { rv = Boolean.valueOf(((String) o).charAt(0) == '\u0001'); } } } return rv; } }