Java Code Examples for java.sql.ResultSet#getBoolean()

The following examples show how to use java.sql.ResultSet#getBoolean() .
Example 1
Project: Library-Assistant   File: BookListController.java    License: Apache License 2.0 6 votes vote down vote up
private void loadData() {
    list.clear();

    DatabaseHandler handler = DatabaseHandler.getInstance();
    String qu = "SELECT * FROM BOOK";
    ResultSet rs = handler.execQuery(qu);
    try {
        while (rs.next()) {
            String titlex = rs.getString("title");
            String author = rs.getString("author");
            String id = rs.getString("id");
            String publisher = rs.getString("publisher");
            Boolean avail = rs.getBoolean("isAvail");

            list.add(new Book(titlex, id, author, publisher, avail));

        }
    } catch (SQLException ex) {
        Logger.getLogger(BookAddController.class.getName()).log(Level.SEVERE, null, ex);
    }

    tableView.setItems(list);
}
 
Example 2
Project: bither-desktop-java   File: AddressProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean hdAccountIsXRandom(int seedId) {
    boolean result = false;
    String sql = "select is_xrandom from hd_account where hd_account_id=?";
    try {
        PreparedStatement statement = this.mDb.getPreparedStatement(sql, new String[]{Integer.toString(seedId)});
        ResultSet rs = statement.executeQuery();
        if (rs.next()) {
            int idColumn = rs.findColumn(AbstractDb.HDAccountColumns.IS_XRANDOM);
            if (idColumn != -1) {
                result = rs.getBoolean(idColumn);
            }
        }
        rs.close();
        statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }

    return result;
}
 
Example 3
Project: wind-im   File: SiteUserGroupDao.java    License: Apache License 2.0 5 votes vote down vote up
public boolean queryMute(String siteUserId, String siteGroupId) throws SQLException {
	long startTime = System.currentTimeMillis();
	boolean result = true;
	String sql = "SELECT mute FROM " + USER_GROUP_TABLE + " WHERE site_user_id=? AND site_group_id=?;";

	Connection conn = null;
	PreparedStatement pst = null;
	ResultSet rs = null;
	try {
		conn = DatabaseConnection.getSlaveConnection();
		pst = conn.prepareStatement(sql);
		pst.setString(1, siteUserId);
		pst.setString(2, siteGroupId);

		rs = pst.executeQuery();
		if (rs.next()) {
			result = rs.getBoolean(1);
		}
	} catch (Exception e) {
		throw e;
	} finally {
		DatabaseConnection.returnConnection(conn, pst, rs);
	}

	LogUtils.dbDebugLog(logger, startTime, result, sql, siteUserId, siteGroupId);
	return result;
}
 
Example 4
Project: registry   File: DefaultStorageDataTypeContext.java    License: Apache License 2.0 5 votes vote down vote up
protected Object getJavaObject(Class columnJavaType, String columnLabel, ResultSet resultSet) throws SQLException {
    if (columnJavaType.equals(String.class)) {
        return resultSet.getString(columnLabel);
    } else if (columnJavaType.equals(Byte.class)) {
        return resultSet.getByte(columnLabel);
    } else if (columnJavaType.equals(Integer.class)) {
        return resultSet.getInt(columnLabel);
    } else if (columnJavaType.equals(Double.class)) {
        return resultSet.getDouble(columnLabel);
    } else if (columnJavaType.equals(Float.class)) {
        return resultSet.getFloat(columnLabel);
    } else if (columnJavaType.equals(Short.class)) {
        return resultSet.getShort(columnLabel);
    } else if (columnJavaType.equals(Boolean.class)) {
        return resultSet.getBoolean(columnLabel);
    } else if (columnJavaType.equals(byte[].class)) {
        return resultSet.getBytes(columnLabel);
    } else if (columnJavaType.equals(Long.class)) {
        return resultSet.getLong(columnLabel);
    } else if (columnJavaType.equals(Date.class)) {
        return resultSet.getDate(columnLabel);
    } else if (columnJavaType.equals(Time.class)) {
        return resultSet.getTime(columnLabel);
    } else if (columnJavaType.equals(Timestamp.class)) {
        return resultSet.getTimestamp(columnLabel);
    } else if (columnJavaType.equals(InputStream.class)) {
        Blob blob = resultSet.getBlob(columnLabel);
        return blob != null ? blob.getBinaryStream() : null;
    } else {
        throw new StorageException("type =  [" + columnJavaType + "] for column [" + columnLabel + "] not supported.");
    }
}
 
Example 5
Project: OpenCue   File: ServiceDaoJdbc.java    License: Apache License 2.0 5 votes vote down vote up
public ServiceOverrideEntity mapRow(ResultSet rs, int rowNum)
        throws SQLException {
    ServiceOverrideEntity s = new ServiceOverrideEntity();
    s.id = rs.getString("pk_show_service");
    s.name = rs.getString("str_name");
    s.minCores = rs.getInt("int_cores_min");
    s.maxCores = rs.getInt("int_cores_max");
    s.minMemory = rs.getLong("int_mem_min");
    s.minGpu = rs.getLong("int_gpu_min");
    s.threadable = rs.getBoolean("b_threadable");
    s.tags = splitTags(rs.getString("str_tags"));
    s.showId = rs.getString("pk_show");
    return s;
}
 
Example 6
Project: Kepler   File: CatalogueDao.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get the catalogue items.
 *
 * @return the list of catalogue items
 */
public static List<CatalogueItem> getItems() {
    List<CatalogueItem> pages = new ArrayList<>();

    Connection sqlConnection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;

    try {
        sqlConnection = Storage.getStorage().getConnection();
        preparedStatement = Storage.getStorage().prepare("SELECT * FROM catalogue_items ORDER BY order_id ASC", sqlConnection);
        resultSet = preparedStatement.executeQuery();

        while (resultSet.next()) {
            CatalogueItem item = new CatalogueItem(resultSet.getInt("id"), resultSet.getString("sale_code"), resultSet.getString("page_id"),
                    resultSet.getInt("order_id"),  resultSet.getInt("price"), resultSet.getBoolean("is_hidden"),
                    resultSet.getInt("definition_id"),  resultSet.getInt("item_specialspriteid"),
                    resultSet.getString("name"), resultSet.getString("description"),
                    resultSet.getBoolean("is_package"), resultSet.getString("package_name"),
                    resultSet.getString("package_description"));

            pages.add(item);
        }

    } catch (Exception e) {
        Storage.logError(e);
    } finally {
        Storage.closeSilently(resultSet);
        Storage.closeSilently(preparedStatement);
        Storage.closeSilently(sqlConnection);
    }

    return pages;
}
 
Example 7
Project: yawp   File: Datastore.java    License: MIT License 5 votes vote down vote up
private boolean existsEntityWithThisKey(final Key key) {
    SqlRunner runner = new DatastoreSqlRunner(key.getKind(), SQL_EXISTS) {
        @Override
        public void bind() {
            bind("key", key);
        }

        @Override
        protected Object collectSingle(ResultSet rs) throws SQLException {
            return rs.getBoolean(1);
        }
    };

    return connectionManager.executeQuery(runner);
}
 
Example 8
Project: cassandra-reaper   File: RepairScheduleStatusMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RepairScheduleStatus map(int index, ResultSet rs, StatementContext ctx) throws SQLException {

  return new RepairScheduleStatus(
      UuidUtil.fromSequenceId(rs.getLong("id")),
      rs.getString("owner"),
      rs.getString("cluster_name"),
      rs.getString("keyspace_name"),
      ImmutableSet.copyOf(getStringArray(rs.getArray("column_families").getArray())),
      RepairSchedule.State.valueOf(rs.getString("state")),
      RepairRunMapper.getDateTimeOrNull(rs, "creation_time"),
      RepairRunMapper.getDateTimeOrNull(rs, "next_activation"),
      RepairRunMapper.getDateTimeOrNull(rs, "pause_time"),
      rs.getDouble("intensity"),
      rs.getBoolean("incremental_repair"),
      rs.getInt("segment_count"),
      RepairParallelism.fromName(
          rs.getString("repair_parallelism")
              .toLowerCase()
              .replace("datacenter_aware", "dc_parallel")),
      rs.getInt("days_between"),
      ImmutableSet.copyOf(
          rs.getArray("nodes") == null
              ? new String[] {}
              : getStringArray(rs.getArray("nodes").getArray())),
      ImmutableSet.copyOf(
          rs.getArray("datacenters") == null
              ? new String[] {}
              : getStringArray(rs.getArray("datacenters").getArray())),
      ImmutableSet.copyOf(
          rs.getArray("blacklisted_tables") == null
              ? new String[] {}
              : getStringArray(rs.getArray("blacklisted_tables").getArray())),
      rs.getInt("segment_count_per_node"),
      rs.getInt("repair_thread_count"),
      UuidUtil.fromSequenceId(rs.getLong("repair_unit_id")));
}
 
Example 9
Project: spliceengine   File: DB_Alias.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public static void doSynonyms(Connection conn) throws SQLException
{
	Statement stmt = conn.createStatement();
	ResultSet rs = stmt.executeQuery("SELECT ALIAS, SCHEMAID, " +
		"ALIASINFO, SYSTEMALIAS FROM SYS.SYSALIASES A WHERE ALIASTYPE='S'");

	boolean firstTime = true;
	while (rs.next()) {
		if (rs.getBoolean(4))
		// it's a system alias, so we ignore it.
			continue;

		String aliasSchema = dblook.lookupSchemaId(rs.getString(2));
		if (dblook.isIgnorableSchema(aliasSchema))
			continue;

		if (firstTime) {
			Logs.reportString("----------------------------------------------");
			Logs.reportMessage("DBLOOK_SynonymHeader");
			Logs.reportString("----------------------------------------------\n");
		}

		String aliasName = rs.getString(1);
		String aliasFullName = dblook.addQuotes(
			dblook.expandDoubleQuotes(aliasName));
		aliasFullName = aliasSchema + "." + aliasFullName;

		Logs.writeToNewDDL("CREATE SYNONYM "+aliasFullName+" FOR "+rs.getString(3));
		Logs.writeStmtEndToNewDDL();
		Logs.writeNewlineToNewDDL();
		firstTime = false;
	}

	rs.close();
	stmt.close();

}
 
Example 10
Project: gemfirexd-oss   File: BaseTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
   * Call consistency checker on the table.
   * <p>
   **/
  protected boolean checkConsistency(
  Connection  conn,
  String      schemaName,
  String      tableName)
throws SQLException
  {
      Statement s = conn.createStatement();

      ResultSet rs = 
          s.executeQuery(
              "values SYSCS_UTIL.CHECK_TABLE('" + 
              schemaName + "', '" + 
              tableName  + "')");

      if (!rs.next())
      {
          if (SanityManager.DEBUG)
          {
              SanityManager.THROWASSERT("no value from values clause.");
          }
      }

      boolean consistent = rs.getBoolean(1);

      rs.close();

      conn.commit();

      return(consistent);
  }
 
Example 11
Project: calcite   File: ReflectiveSchemaTest.java    License: Apache License 2.0 5 votes vote down vote up
private Object get(ResultSet input) throws SQLException {
  final int type = input.getMetaData().getColumnType(1);
  switch (type) {
  case java.sql.Types.BOOLEAN:
    return input.getBoolean(1);
  case java.sql.Types.TINYINT:
    return input.getByte(1);
  case java.sql.Types.SMALLINT:
    return input.getShort(1);
  case java.sql.Types.INTEGER:
    return input.getInt(1);
  case java.sql.Types.BIGINT:
    return input.getLong(1);
  case java.sql.Types.REAL:
    return input.getFloat(1);
  case java.sql.Types.DOUBLE:
    return input.getDouble(1);
  case java.sql.Types.CHAR:
  case java.sql.Types.VARCHAR:
    return input.getString(1);
  case java.sql.Types.DATE:
    return input.getDate(1);
  case java.sql.Types.TIME:
    return input.getTime(1);
  case java.sql.Types.TIMESTAMP:
    return input.getTimestamp(1);
  case java.sql.Types.DECIMAL:
    return input.getBigDecimal(1);
  default:
    throw new AssertionError(type);
  }
}
 
Example 12
Project: jqm   File: JobDef.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * ResultSet is not modified (no rs.next called).
 *
 * @param rs
 * @return
 */
static JobDef map(ResultSet rs, int colShift)
{
    JobDef tmp = new JobDef();

    try
    {
        tmp.id = rs.getInt(1 + colShift);
        tmp.application = rs.getString(2 + colShift);
        tmp.applicationName = rs.getString(3 + colShift);
        tmp.canBeRestarted = true;
        tmp.classLoader = rs.getInt(4 + colShift) > 0 ? rs.getInt(4 + colShift) : null;
        tmp.description = rs.getString(5 + colShift);
        tmp.enabled = rs.getBoolean(6 + colShift);
        tmp.external = rs.getBoolean(7 + colShift);
        tmp.highlander = rs.getBoolean(8 + colShift);
        tmp.jarPath = rs.getString(9 + colShift);
        tmp.javaClassName = rs.getString(10 + colShift);
        tmp.javaOpts = rs.getString(11 + colShift);
        tmp.keyword1 = rs.getString(12 + colShift);
        tmp.keyword2 = rs.getString(13 + colShift);
        tmp.keyword3 = rs.getString(14 + colShift);
        tmp.maxTimeRunning = rs.getInt(15 + colShift);
        tmp.module = rs.getString(16 + colShift);
        tmp.pathType = PathType.valueOf(rs.getString(17 + colShift));
        tmp.queue_id = rs.getInt(18 + colShift);
        tmp.priority = rs.getInt(19 + colShift) > 0 ? rs.getInt(19 + colShift) : null;
    }
    catch (SQLException e)
    {
        throw new DatabaseException(e);
    }
    return tmp;
}
 
Example 13
Project: presto   File: Table.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Table map(int index, ResultSet r, StatementContext ctx)
        throws SQLException
{
    return new Table(
            r.getLong("table_id"),
            Optional.ofNullable(getBoxedLong(r, "distribution_id")),
            Optional.ofNullable(r.getString("distribution_name")),
            getOptionalInt(r, "bucket_count"),
            getOptionalLong(r, "temporal_column_id"),
            r.getBoolean("organization_enabled"));
}
 
Example 14
Project: FunnyGuilds   File: DatabaseGuild.java    License: Apache License 2.0 4 votes vote down vote up
public static Guild deserialize(ResultSet rs) {
    if (rs == null) {
        return null;
    }
    
    try {
        String id = rs.getString("uuid");
        String name = rs.getString("name");
        String tag = rs.getString("tag");
        String os = rs.getString("owner");
        String dp = rs.getString("deputy");
        String home = rs.getString("home");
        String regionName = rs.getString("region");
        String m = rs.getString("members");
        boolean pvp = rs.getBoolean("pvp");
        long born = rs.getLong("born");
        long validity = rs.getLong("validity");
        long attacked = rs.getLong("attacked");
        long ban = rs.getLong("ban");
        int lives = rs.getInt("lives");

        if (name == null || tag == null || os == null) {
            FunnyGuilds.getInstance().getPluginLogger().error("Cannot deserialize guild! Caused by: uuid/name/tag/owner is null");
            return null;
        }

        UUID uuid = UUID.randomUUID();
        if (id != null && !id.isEmpty()) {
            uuid = UUID.fromString(id);
        }
        
        final User owner = User.get(os);
        
        Set<User> deputies = new HashSet<>();
        if (dp != null && !dp.isEmpty()) {
            deputies = UserUtils.getUsers(ChatUtils.fromString(dp));
        }

        Set<User> members = new HashSet<>();
        if (m != null && !m.equals("")) {
            members = UserUtils.getUsers(ChatUtils.fromString(m));
        }

        if (born == 0) {
            born = System.currentTimeMillis();
        }
        
        if (validity == 0) {
            validity = System.currentTimeMillis() + FunnyGuilds.getInstance().getPluginConfiguration().validityStart;
        }
        
        if (lives == 0) {
            lives = FunnyGuilds.getInstance().getPluginConfiguration().warLives;
        }

        final Object[] values = new Object[17];
        
        values[0] = uuid;
        values[1] = name;
        values[2] = tag;
        values[3] = owner;
        values[4] = LocationUtils.parseLocation(home);
        values[5] = RegionUtils.get(regionName);
        values[6] = members;
        values[7] = Sets.newHashSet();
        values[9] = born;
        values[10] = validity;
        values[11] = attacked;
        values[12] = lives;
        values[13] = ban;
        values[14] = deputies;
        values[15] = pvp;

        return DeserializationUtils.deserializeGuild(values);
    }
    catch (Exception ex) {
        FunnyGuilds.getInstance().getPluginLogger().error("Could not deserialize guild", ex);
    }
    
    return null;
}
 
Example 15
Project: jsqsh   File: Diff.java    License: Apache License 2.0 4 votes vote down vote up
private Object[] getRow(ResultSet set)
    throws SQLException {
    
    ResultSetMetaData meta = set.getMetaData();
    int ncols = meta.getColumnCount();
    Object []values = new Object[ncols];
    for (int c = 1; c <= ncols; c++) {
        
        int type = meta.getColumnType(c);
        switch (type) {
            
            case Types.NUMERIC:
            case Types.DECIMAL:
                values[c - 1] = set.getBigDecimal(c);
                break;
                
            case Types.BINARY:
            case Types.VARBINARY:
            case Types.LONGVARBINARY:
                ByteFormatter f = new ByteFormatter(
                    meta.getColumnDisplaySize(c));
                values[c - 1] = f.format(set.getObject(c));
                break;
                
            case Types.BLOB:
                BlobFormatter b = new BlobFormatter();
                values[c - 1] = b.format(set.getObject(c));
                break;
                
            case Types.CLOB:
                ClobFormatter cf= new ClobFormatter();
                values[c - 1] = cf.format(set.getObject(c));
                break;
                
            case Types.BOOLEAN:
                values[c - 1] = set.getBoolean(c);
                break;
                
            case Types.CHAR:
            case Types.VARCHAR:
            /* case Types.NVARCHAR:*/
            /* case Types.LONGNVARCHAR: */
            case Types.LONGVARCHAR:
            /* case Types.NCHAR: */
                values[c - 1] = set.getString(c);
                break;
                
            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP:
                values[c - 1] = set.getObject(c);
                break;
                
            case Types.DOUBLE:
            case Types.FLOAT:
            case Types.REAL:
                values[c - 1] = set.getDouble(c);
                break;
               
            case Types.BIT:
            case Types.TINYINT:
            case Types.SMALLINT:
            case Types.INTEGER:
            case Types.BIGINT:
                values[c - 1] = new Long(set.getLong(c));
                break;
                
            default:
                System.err.println("WARNING: I do not understand "
                    + "datatype #" + type + " ("
                    + meta.getColumnTypeName(c) + ") in column #"
                    + c + ". No comparison will be performed.");
                values[c - 1] = set.getObject(c);
                break;
        }
        
        if (set.wasNull()) {
            
            values[c - 1] = "NULL";
        }
    }
    
    return values;
}
 
Example 16
Project: spring-analysis-note   File: GenericTableMetaDataProvider.java    License: MIT License 4 votes vote down vote up
/**
 * Method supporting the meta-data processing for a table's columns.
 */
private void processTableColumns(DatabaseMetaData databaseMetaData, TableMetaData tmd) {
	ResultSet tableColumns = null;
	String metaDataCatalogName = metaDataCatalogNameToUse(tmd.getCatalogName());
	String metaDataSchemaName = metaDataSchemaNameToUse(tmd.getSchemaName());
	String metaDataTableName = tableNameToUse(tmd.getTableName());
	if (logger.isDebugEnabled()) {
		logger.debug("Retrieving meta-data for " + metaDataCatalogName + '/' +
				metaDataSchemaName + '/' + metaDataTableName);
	}
	try {
		tableColumns = databaseMetaData.getColumns(
				metaDataCatalogName, metaDataSchemaName, metaDataTableName, null);
		while (tableColumns.next()) {
			String columnName = tableColumns.getString("COLUMN_NAME");
			int dataType = tableColumns.getInt("DATA_TYPE");
			if (dataType == Types.DECIMAL) {
				String typeName = tableColumns.getString("TYPE_NAME");
				int decimalDigits = tableColumns.getInt("DECIMAL_DIGITS");
				// Override a DECIMAL data type for no-decimal numerics
				// (this is for better Oracle support where there have been issues
				// using DECIMAL for certain inserts (see SPR-6912))
				if ("NUMBER".equals(typeName) && decimalDigits == 0) {
					dataType = Types.NUMERIC;
					if (logger.isDebugEnabled()) {
						logger.debug("Overriding meta-data: " + columnName + " now NUMERIC instead of DECIMAL");
					}
				}
			}
			boolean nullable = tableColumns.getBoolean("NULLABLE");
			TableParameterMetaData meta = new TableParameterMetaData(columnName, dataType, nullable);
			this.tableParameterMetaData.add(meta);
			if (logger.isDebugEnabled()) {
				logger.debug("Retrieved meta-data: " + meta.getParameterName() + " " +
						meta.getSqlType() + " " + meta.isNullable());
			}
		}
	}
	catch (SQLException ex) {
		if (logger.isWarnEnabled()) {
			logger.warn("Error while retrieving meta-data for table columns: " + ex.getMessage());
		}
	}
	finally {
		JdbcUtils.closeResultSet(tableColumns);
	}
}
 
Example 17
Project: gemfirexd-oss   File: GemFireXDResolver.java    License: Apache License 2.0 4 votes vote down vote up
private OneField parseField(ResultSet rs, int i) throws Exception {
  // Indexing in rs starts at 1.
  final DataType type = this.columnTypeMapping[i];
  switch (type) {
    case SMALLINT:
      return new OneField(DataType.SMALLINT.getOID(),
          rs.getShort(this.columnIndexMapping[i]));

    case INTEGER:
      return new OneField(DataType.INTEGER.getOID(),
          rs.getInt(this.columnIndexMapping[i]));

    case BIGINT:
      return new OneField(DataType.BIGINT.getOID(),
          rs.getLong(this.columnIndexMapping[i]));

    case REAL:
      return new OneField(DataType.REAL.getOID(),
          rs.getFloat(this.columnIndexMapping[i]));

    case FLOAT8:
      return new OneField(DataType.FLOAT8.getOID(),
          rs.getDouble(this.columnIndexMapping[i]));

    case VARCHAR:
      return new OneField(DataType.VARCHAR.getOID(),
          rs.getString(this.columnIndexMapping[i]));

    case BOOLEAN:
      return new OneField(DataType.BOOLEAN.getOID(),
          rs.getBoolean(this.columnIndexMapping[i]));

    case NUMERIC:
      return new OneField(DataType.NUMERIC.getOID(),
          rs.getBigDecimal(this.columnIndexMapping[i]));

    case TIMESTAMP:
      return new OneField(DataType.TIMESTAMP.getOID(),
          rs.getTimestamp(this.columnIndexMapping[i]));

    case DATE:
      return new OneField(DataType.DATE.getOID(),
          rs.getDate(this.columnIndexMapping[i]));

    case TIME:
      return new OneField(DataType.TIME.getOID(),
          rs.getTime(this.columnIndexMapping[i]));

    case CHAR:
      return new OneField(DataType.CHAR.getOID(),
          rs.getString(this.columnIndexMapping[i]));

    case BPCHAR:
      return new OneField(DataType.BPCHAR.getOID(),
          rs.getString(this.columnIndexMapping[i]));

    case BYTEA:
      return new OneField(DataType.BYTEA.getOID(),
          rs.getBytes(this.columnIndexMapping[i]));

    case TEXT:
      return new OneField(DataType.TEXT.getOID(),
          rs.getString(this.columnIndexMapping[i]));

    default:
      throw new Exception("Column type " + type + " is not supported.");
  }
}
 
Example 18
Project: disconf   File: MapperUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 在rs中获取column字段的typeClass型的值
 *
 * @param rs
 * @param column
 * @param paramClass
 *
 * @return
 *
 * @throws SQLException
 */
public static Object getValue4Type(ResultSet rs, String column, Class<?> typeClass) throws SQLException {

    if (Collection.class.isAssignableFrom(typeClass)) {
        return null;
    }

    try {
        rs.findColumn(column);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    if (typeClass.equals(Integer.class) || typeClass.equals(Integer.TYPE)) {
        return rs.getInt(column);
    }

    if (typeClass.equals(Long.class) || typeClass.equals(Long.TYPE)) {
        return rs.getLong(column);
    }

    if (typeClass.equals(Boolean.class) || typeClass.equals(Boolean.TYPE)) {
        return rs.getBoolean(column);
    }

    if (typeClass.equals(Float.class) || typeClass.equals(Float.TYPE)) {
        return rs.getFloat(column);
    }

    if (typeClass.equals(Double.class) || typeClass.equals(Double.TYPE)) {
        return rs.getDouble(column);
    }

    if (typeClass.equals(Byte.class) || typeClass.equals(Byte.TYPE)) {
        return rs.getByte(column);
    }

    if (typeClass.equals(String.class)) {
        return rs.getString(column);
    }

    if (Date.class.isAssignableFrom(typeClass)) {
        return rs.getTimestamp(column);
    }

    if (java.sql.Date.class.isAssignableFrom(typeClass)) {
        return rs.getDate(column);
    }

    return rs.getObject(column);
}
 
Example 19
Project: ralasafe   File: ResultSetReader.java    License: MIT License 4 votes vote down vote up
public Object reader(ResultSet rs, String columnName)
		throws SQLException {
	return new Boolean(rs.getBoolean(columnName));
}
 
Example 20
Project: disconf   File: MapperUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 在rs中获取column字段的typeClass型的值
 *
 * @param rs
 * @param column
 * @param paramClass
 *
 * @return
 *
 * @throws SQLException
 */
public static Object getValue4Type(ResultSet rs, String column, Class<?> typeClass) throws SQLException {

    if (Collection.class.isAssignableFrom(typeClass)) {
        return null;
    }

    try {
        rs.findColumn(column);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    if (typeClass.equals(Integer.class) || typeClass.equals(Integer.TYPE)) {
        return rs.getInt(column);
    }

    if (typeClass.equals(Long.class) || typeClass.equals(Long.TYPE)) {
        return rs.getLong(column);
    }

    if (typeClass.equals(Boolean.class) || typeClass.equals(Boolean.TYPE)) {
        return rs.getBoolean(column);
    }

    if (typeClass.equals(Float.class) || typeClass.equals(Float.TYPE)) {
        return rs.getFloat(column);
    }

    if (typeClass.equals(Double.class) || typeClass.equals(Double.TYPE)) {
        return rs.getDouble(column);
    }

    if (typeClass.equals(Byte.class) || typeClass.equals(Byte.TYPE)) {
        return rs.getByte(column);
    }

    if (typeClass.equals(String.class)) {
        return rs.getString(column);
    }

    if (Date.class.isAssignableFrom(typeClass)) {
        return rs.getTimestamp(column);
    }

    if (java.sql.Date.class.isAssignableFrom(typeClass)) {
        return rs.getDate(column);
    }

    return rs.getObject(column);
}