Java Code Examples for java.sql.ResultSet.getByte()

The following are Jave code examples for showing how to use getByte() of the java.sql.ResultSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: adept   File: PrimitiveHandler.java   View Source Code Vote up 6 votes
/**
 * 根据JavaBean属性类型名称得到Java8种原始类型下的ResultSet对应序号列的值.
 * @param rs ResultSet实例
 * @param colNum 结果集列序号
 * @param propType 属性类型名称
 * @return 字段值
 */
@Override
public Object getColumnValue(ResultSet rs, int colNum, Class<?> propType) throws SQLException {
    // 将几种常用原始类型放前面优先判断并直接返回结果
    String propTypeName = propType.getName();
    if ("int".equals(propTypeName)) {
        return rs.getInt(colNum);
    } else if ("long".equals(propTypeName)) {
        return rs.getLong(colNum);
    } else if ("double".equals(propTypeName)) {
        return rs.getDouble(colNum);
    } else if ("boolean".equals(propTypeName)) {
        return rs.getBoolean(colNum);
    } else if ("byte".equals(propTypeName)) {
        return rs.getByte(colNum);
    } else if ("short".equals(propTypeName)) {
        return rs.getShort(colNum);
    } else if ("float".equals(propTypeName)) {
        return rs.getFloat(colNum);
    } else if ("char".equals(propTypeName)) {
        return rs.getString(colNum);
    }
    return null;
}
 
Example 2
Project: AeroStory   File: MapleClient.java   View Source Code Vote up 6 votes
public boolean acceptToS() {
    boolean disconnectForBeingAFaggot = false;
    if (accountName == null) {
        return true;
    }
    try {
        PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT `tos` FROM accounts WHERE id = ?");
        ps.setInt(1, accId);
        ResultSet rs = ps.executeQuery();

        if (rs.next()) {
            if (rs.getByte("tos") == 1) {
                disconnectForBeingAFaggot = true;
            }
        }
        ps.close();
        rs.close();
        ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET tos = 1 WHERE id = ?");
        ps.setInt(1, accId);
        ps.executeUpdate();
        ps.close();
    } catch (SQLException e) {
    }
    return disconnectForBeingAFaggot;
}
 
Example 3
Project: AeroStory   File: PlayerNPCs.java   View Source Code Vote up 6 votes
public PlayerNPCs(ResultSet rs) {
    try {
        CY = rs.getInt("cy");
        name = rs.getString("name");
        hair = rs.getInt("hair");
        face = rs.getInt("face");
        skin = rs.getByte("skin");
        FH = rs.getInt("Foothold");
        RX0 = rs.getInt("rx0");
        RX1 = rs.getInt("rx1");
        npcId = rs.getInt("ScriptId");
        setPosition(new Point(rs.getInt("x"), CY));
        PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT equippos, equipid FROM playernpcs_equip WHERE NpcId = ?");
        ps.setInt(1, rs.getInt("id"));
        ResultSet rs2 = ps.executeQuery();
        while (rs2.next()) {
            equips.put(rs2.getByte("equippos"), rs2.getInt("equipid"));
        }
        rs2.close();
        ps.close();
    } catch (SQLException e) {
    }
}
 
Example 4
Project: burstcoin   File: Asset.java   View Source Code Vote up 5 votes
private Asset(ResultSet rs) throws SQLException {
    this.assetId = rs.getLong("id");
    this.dbKey = assetDbKeyFactory.newKey(this.assetId);
    this.accountId = rs.getLong("account_id");
    this.name = rs.getString("name");
    this.description = rs.getString("description");
    this.quantityQNT = rs.getLong("quantity");
    this.decimals = rs.getByte("decimals");
}
 
Example 5
Project: burstcoin   File: Poll.java   View Source Code Vote up 5 votes
private Poll(ResultSet rs) throws SQLException {
    this.id = rs.getLong("id");
    this.dbKey = pollDbKeyFactory.newKey(this.id);
    this.name = rs.getString("name");
    this.description = rs.getString("description");
    this.options = (String[])rs.getArray("options").getArray();
    this.minNumberOfOptions = rs.getByte("min_num_options");
    this.maxNumberOfOptions = rs.getByte("max_num_options");
    this.optionsAreBinary = rs.getBoolean("binary_options");
}
 
Example 6
Project: AdamantineShield   File: BlockLookupResult.java   View Source Code Vote up 5 votes
protected void readResult(ResultSet results) throws SQLException {
	while (results.next()) {
		Vector3i pos = new Vector3i(results.getInt("x"), results.getInt("y"), results.getInt("z"));
		UUID world = UUID.fromString(results.getString("world"));
		ActionType type = ActionType.valueCache[results.getByte("type")];
		String cause = results.getString("cause");
		String data = results.getString("data");
		BlockType block = Sponge.getRegistry().getType(BlockType.class, results.getString("AS_Id.value")).get();
		boolean rolledBack = results.getBoolean("rolled_back");
		long timestamp = results.getLong("time");
		lines.add(new LookupLine(pos, world, type, cause, data, block, 1, 0, rolledBack, timestamp));
	}
}
 
Example 7
Project: AdamantineShield   File: ContainerLookupResult.java   View Source Code Vote up 5 votes
protected void readResult(ResultSet results) throws SQLException {
	while (results.next()) {
		Vector3i pos = new Vector3i(results.getInt("x"), results.getInt("y"), results.getInt("z"));
		UUID world = UUID.fromString(results.getString("world"));
		ActionType type = ActionType.valueCache[results.getByte("type")];
		String cause = results.getString("cause");
		String data = results.getString("data");
		ItemType item = Sponge.getRegistry().getType(ItemType.class, results.getString("AS_Id.value")).get();
		int count = results.getByte("count");
		int slot = results.getInt("slot");
		boolean rolledBack = results.getBoolean("rolled_back");
		long timestamp = results.getLong("time");
		lines.add(new LookupLine(pos, world, type, cause, data, item, count, slot, rolledBack, timestamp));
	}
}
 
Example 8
Project: calcite-avatica   File: AvaticaResultSetConversionsTest.java   View Source Code Vote up 5 votes
public void testGetByte(ResultSet resultSet) throws SQLException {
  try {
    resultSet.getByte(ordinal);
    fail("Was expecting to throw SQLDataException");
  } catch (Exception e) {
    assertThat(e, isA((Class) SQLDataException.class)); // success
  }
}
 
Example 9
Project: Lucid2.0   File: PlayerNPC.java   View Source Code Vote up 5 votes
public PlayerNPC(ResultSet rs) throws Exception {
    super(rs.getInt("ScriptId"), rs.getString("name"));
    hair = rs.getInt("hair");
    secondHair = hair;
    face = rs.getInt("face");
    secondFace = face;
    mapid = rs.getInt("map");
    skin = rs.getByte("skin");
    secondSkin = skin;
    charId = rs.getInt("charid");
    gender = rs.getByte("gender");
    secondGender = gender;
    job = rs.getShort("job");
    elf = rs.getInt("elf");
    faceMarking = rs.getInt("faceMarking");
    setCoords(rs.getInt("x"), rs.getInt("y"), rs.getInt("dir"), rs.getInt("Foothold"));
    String[] pet = rs.getString("pets").split(",");
    for (int i = 0; i < 3; i++) {
        if (pet[i] != null) {
            pets[i] = Integer.parseInt(pet[i]);
        } else {
            pets[i] = 0;
        }
    }

    Connection con = DatabaseConnection.getConnection();
    try (PreparedStatement ps = con.prepareStatement("SELECT * FROM playernpcs_equip WHERE NpcId = ?")) {
        ps.setInt(1, getId());
        try (ResultSet rs2 = ps.executeQuery()) {
            while (rs2.next()) {
                equips.put(rs2.getByte("equippos"), rs2.getInt("equipid"));
                secondEquips.put(rs2.getByte("equippos"), rs2.getInt("equipid"));
            }
        }
    }
}
 
Example 10
Project: Lucid2.0   File: MapleStorage.java   View Source Code Vote up 5 votes
public static MapleStorage loadStorage(int id) {
    MapleStorage ret = null;
    int storeId;
    try {
        Connection con = DatabaseConnection.getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT * FROM storages WHERE accountid = ?");
        ps.setInt(1, id);
        ResultSet rs = ps.executeQuery();

        if (rs.next()) {
            storeId = rs.getInt("storageid");
            ret = new MapleStorage(storeId, rs.getByte("slots"), rs.getInt("meso"), id);
            rs.close();
            ps.close();

            for (Pair<Item, MapleInventoryType> mit : ItemLoader.STORAGE.loadItems(false, id).values()) {
                ret.items.add(mit.getLeft());
            }
        } else {
            storeId = create(id);
            ret = new MapleStorage(storeId, (byte) 4, 0, id);
            rs.close();
            ps.close();
        }
    } catch (SQLException ex) {
        System.err.println("Error loading storage" + ex);
    }
    return ret;
}
 
Example 11
Project: burstcoin   File: TransactionDb.java   View Source Code Vote up 4 votes
static TransactionImpl loadTransaction(Connection con, ResultSet rs) throws NxtException.ValidationException {
    try {

        byte type = rs.getByte("type");
        byte subtype = rs.getByte("subtype");
        int timestamp = rs.getInt("timestamp");
        short deadline = rs.getShort("deadline");
        byte[] senderPublicKey = rs.getBytes("sender_public_key");
        long amountNQT = rs.getLong("amount");
        long feeNQT = rs.getLong("fee");
        byte[] referencedTransactionFullHash = rs.getBytes("referenced_transaction_full_hash");
        int ecBlockHeight = rs.getInt("ec_block_height");
        long ecBlockId = rs.getLong("ec_block_id");
        byte[] signature = rs.getBytes("signature");
        long blockId = rs.getLong("block_id");
        int height = rs.getInt("height");
        long id = rs.getLong("id");
        long senderId = rs.getLong("sender_id");
        byte[] attachmentBytes = rs.getBytes("attachment_bytes");
        int blockTimestamp = rs.getInt("block_timestamp");
        byte[] fullHash = rs.getBytes("full_hash");
        byte version = rs.getByte("version");

        ByteBuffer buffer = null;
        if (attachmentBytes != null) {
            buffer = ByteBuffer.wrap(attachmentBytes);
            buffer.order(ByteOrder.LITTLE_ENDIAN);
        }

        TransactionType transactionType = TransactionType.findTransactionType(type, subtype);
        TransactionImpl.BuilderImpl builder = new TransactionImpl.BuilderImpl(version, senderPublicKey,
                amountNQT, feeNQT, timestamp, deadline,
                transactionType.parseAttachment(buffer, version))
                .referencedTransactionFullHash(referencedTransactionFullHash)
                .signature(signature)
                .blockId(blockId)
                .height(height)
                .id(id)
                .senderId(senderId)
                .blockTimestamp(blockTimestamp)
                .fullHash(fullHash);
        if (transactionType.hasRecipient()) {
            long recipientId = rs.getLong("recipient_id");
            if (! rs.wasNull()) {
                builder.recipientId(recipientId);
            }
        }
        if (rs.getBoolean("has_message")) {
            builder.message(new Appendix.Message(buffer, version));
        }
        if (rs.getBoolean("has_encrypted_message")) {
            builder.encryptedMessage(new Appendix.EncryptedMessage(buffer, version));
        }
        if (rs.getBoolean("has_public_key_announcement")) {
            builder.publicKeyAnnouncement(new Appendix.PublicKeyAnnouncement(buffer, version));
        }
        if (rs.getBoolean("has_encrypttoself_message")) {
            builder.encryptToSelfMessage(new Appendix.EncryptToSelfMessage(buffer, version));
        }
        if (version > 0) {
            builder.ecBlockHeight(ecBlockHeight);
            builder.ecBlockId(ecBlockId);
        }

        return builder.build();

    } catch (SQLException e) {
        throw new RuntimeException(e.toString(), e);
    }
}
 
Example 12
Project: kafka-connect-cdc-mssql   File: MsSqlChange.java   View Source Code Vote up 4 votes
public MsSqlChange build(TableMetadataProvider.TableMetadata tableMetadata, ResultSet resultSet, Time time) throws SQLException {
  MsSqlChange change = new MsSqlChange();
  change.timestamp = time.milliseconds();
  change.databaseName = tableMetadata.databaseName();
  change.schemaName = tableMetadata.schemaName();
  change.tableName = tableMetadata.tableName();

  final long sysChangeVersion = resultSet.getLong("__metadata_sys_change_version");
  final long sysChangeCreationVersion = resultSet.getLong("__metadata_sys_change_creation_version");
  final String changeOperation = resultSet.getString("__metadata_sys_change_operation");

  change.metadata = ImmutableMap.of(
      "sys_change_operation", changeOperation,
      "sys_change_creation_version", String.valueOf(sysChangeCreationVersion),
      "sys_change_version", String.valueOf(sysChangeVersion)
  );

  switch (changeOperation) {
    case "I":
      change.changeType = ChangeType.INSERT;
      break;
    case "U":
      change.changeType = ChangeType.UPDATE;
      break;
    case "D":
      change.changeType = ChangeType.DELETE;
      break;
    default:
      throw new UnsupportedOperationException(
          String.format("Unsupported sys_change_operation of '%s'", changeOperation)
      );
  }
  log.trace("build() - changeType = {}", change.changeType);

  change.keyColumns = new ArrayList<>(tableMetadata.keyColumns().size());
  change.valueColumns = new ArrayList<>(tableMetadata.columnSchemas().size());

  for (Map.Entry<String, Schema> kvp : tableMetadata.columnSchemas().entrySet()) {
    String columnName = kvp.getKey();
    Schema schema = kvp.getValue();
    Object value;
    if (Schema.Type.INT8 == schema.type()) {
      // Really lame Microsoft. A tiny int is stored as a single byte with a value of 0-255.
      // Explain how this should be returned as a short?
      value = resultSet.getByte(columnName);
    } else if (Schema.Type.INT32 == schema.type() &&
        Date.LOGICAL_NAME.equals(schema.name())) {
      value = new java.util.Date(
          resultSet.getDate(columnName, calendar).getTime()
      );
    } else if (Schema.Type.INT32 == schema.type() &&
        org.apache.kafka.connect.data.Time.LOGICAL_NAME.equals(schema.name())) {
      value = new java.util.Date(
          resultSet.getTime(columnName, calendar).getTime()
      );
    } else {
      value = resultSet.getObject(columnName);
    }

    log.trace("build() - columnName = '{}' value = '{}'", columnName, value);
    MsSqlColumnValue columnValue = new MsSqlColumnValue(columnName, schema, value);
    change.valueColumns.add(columnValue);
    if (tableMetadata.keyColumns().contains(columnName)) {
      change.keyColumns.add(columnValue);
    }
  }

  return change;
}
 
Example 13
Project: tangyuan2   File: ByteTypeHandler.java   View Source Code Vote up 4 votes
@Override
public Byte getNullableResult(ResultSet rs, String columnName) throws SQLException {
	return rs.getByte(columnName);
}
 
Example 14
Project: tangyuan2   File: ByteTypeHandler.java   View Source Code Vote up 4 votes
@Override
public Byte getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
	return rs.getByte(columnIndex);
}
 
Example 15
Project: jsf-core   File: ConvertableEnumTypeHandler.java   View Source Code Vote up 4 votes
@Override
protected Byte getValue(ResultSet rs, String columnName)
        throws SQLException {
    return rs.getByte(columnName);
}
 
Example 16
Project: jsf-core   File: ConvertableEnumTypeHandler.java   View Source Code Vote up 4 votes
@Override
protected Byte getValue(ResultSet rs, int columnIndex)
        throws SQLException {
    return rs.getByte(columnIndex);
}
 
Example 17
Project: calcite-avatica   File: JdbcResultSet.java   View Source Code Vote up 4 votes
private static Object getValue(ResultSet resultSet, int type, int j,
    Calendar calendar) throws SQLException {
  switch (type) {
  case Types.BIGINT:
    final long aLong = resultSet.getLong(j + 1);
    return aLong == 0 && resultSet.wasNull() ? null : aLong;
  case Types.INTEGER:
    final int anInt = resultSet.getInt(j + 1);
    return anInt == 0 && resultSet.wasNull() ? null : anInt;
  case Types.SMALLINT:
    final short aShort = resultSet.getShort(j + 1);
    return aShort == 0 && resultSet.wasNull() ? null : aShort;
  case Types.TINYINT:
    final byte aByte = resultSet.getByte(j + 1);
    return aByte == 0 && resultSet.wasNull() ? null : aByte;
  case Types.DOUBLE:
  case Types.FLOAT:
    final double aDouble = resultSet.getDouble(j + 1);
    return aDouble == 0D && resultSet.wasNull() ? null : aDouble;
  case Types.REAL:
    final float aFloat = resultSet.getFloat(j + 1);
    return aFloat == 0D && resultSet.wasNull() ? null : aFloat;
  case Types.DATE:
    final Date aDate = resultSet.getDate(j + 1, calendar);
    return aDate == null
        ? null
        : (int) (aDate.getTime() / DateTimeUtils.MILLIS_PER_DAY);
  case Types.TIME:
    final Time aTime = resultSet.getTime(j + 1, calendar);
    return aTime == null
        ? null
        : (int) (aTime.getTime() % DateTimeUtils.MILLIS_PER_DAY);
  case Types.TIMESTAMP:
    final Timestamp aTimestamp = resultSet.getTimestamp(j + 1, calendar);
    return aTimestamp == null ? null : aTimestamp.getTime();
  case Types.ARRAY:
    final Array array = resultSet.getArray(j + 1);
    if (null == array) {
      return null;
    }
    try {
      // Recursively extracts an Array using its ResultSet-representation
      return extractUsingResultSet(array, calendar);
    } catch (UnsupportedOperationException | SQLFeatureNotSupportedException e) {
      // Not every database might implement Array.getResultSet(). This call
      // assumes a non-nested array (depends on the db if that's a valid assumption)
      return extractUsingArray(array, calendar);
    }
  case Types.STRUCT:
    Struct struct = resultSet.getObject(j + 1, Struct.class);
    Object[] attrs = struct.getAttributes();
    List<Object> list = new ArrayList<>(attrs.length);
    for (Object o : attrs) {
      list.add(o);
    }
    return list;
  default:
    return resultSet.getObject(j + 1);
  }
}
 
Example 18
Project: calcite-avatica   File: ColumnMetaData.java   View Source Code Vote up 4 votes
/** Returns the value of a column of this type from a result set. */
public Object jdbcGet(ResultSet resultSet, int i) throws SQLException {
  switch (this) {
  case PRIMITIVE_BOOLEAN:
    return resultSet.getBoolean(i);
  case PRIMITIVE_BYTE:
    return resultSet.getByte(i);
  case PRIMITIVE_SHORT:
    return resultSet.getShort(i);
  case PRIMITIVE_INT:
    return resultSet.getInt(i);
  case PRIMITIVE_LONG:
    return resultSet.getLong(i);
  case PRIMITIVE_FLOAT:
    return resultSet.getFloat(i);
  case PRIMITIVE_DOUBLE:
    return resultSet.getDouble(i);
  case BOOLEAN:
    final boolean aBoolean = resultSet.getBoolean(i);
    return resultSet.wasNull() ? null : aBoolean;
  case BYTE:
    final byte aByte = resultSet.getByte(i);
    return resultSet.wasNull() ? null : aByte;
  case SHORT:
    final short aShort = resultSet.getShort(i);
    return resultSet.wasNull() ? null : aShort;
  case INTEGER:
    final int anInt = resultSet.getInt(i);
    return resultSet.wasNull() ? null : anInt;
  case LONG:
    final long aLong = resultSet.getLong(i);
    return resultSet.wasNull() ? null : aLong;
  case FLOAT:
    final float aFloat = resultSet.getFloat(i);
    return resultSet.wasNull() ? null : aFloat;
  case DOUBLE:
    final double aDouble = resultSet.getDouble(i);
    return resultSet.wasNull() ? null : aDouble;
  case JAVA_SQL_DATE:
    return resultSet.getDate(i);
  case JAVA_SQL_TIME:
    return resultSet.getTime(i);
  case JAVA_SQL_TIMESTAMP:
    return resultSet.getTimestamp(i);
  case ARRAY:
    return resultSet.getArray(i);
  case STRUCT:
    return resultSet.getObject(i, Struct.class);
  default:
    return resultSet.getObject(i);
  }
}
 
Example 19
Project: Lucid2.0   File: MapleShop.java   View Source Code Vote up 4 votes
public static MapleShop createFromDB(int id, boolean isShopId) {
    MapleShop ret = null;

    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    try {
        Connection con = DatabaseConnection.getConnection();
        PreparedStatement ps = con.prepareStatement(isShopId ? "SELECT * FROM shops WHERE shopid = ?" : "SELECT * FROM shops WHERE npcid = ?");
        int shopId;
        ps.setInt(1, id);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            shopId = rs.getInt("shopid");
            ret = new MapleShop(shopId, rs.getInt("npcid"));
            rs.close();
            ps.close();
        } else {
            rs.close();
            ps.close();
            return null;
        }
        ps = con.prepareStatement("SELECT * FROM shopitems WHERE shopid = ? ORDER BY position ASC");
        ps.setInt(1, shopId);
        rs = ps.executeQuery();
        List<Integer> recharges = new ArrayList<Integer>(rechargeableItems);
        while (rs.next()) {
            if (ii.itemExists(rs.getInt("itemid"))) {
                if ((GameConstants.isThrowingStar(rs.getInt("itemid"))) || (GameConstants.isBullet(rs.getInt("itemid")))) {
                    MapleShopItem starItem = new MapleShopItem((short) rs.getShort("buyable"), ii.getSlotMax(rs.getInt("itemid")), rs.getInt("itemid"), rs.getInt("price"), (short) rs.getInt("position"), rs.getInt("reqitem"), rs.getInt("reqitemq"), rs.getByte("rank"), rs.getInt("category"), rs.getInt("minLevel"), rs.getInt("expiration"), false);
                    ret.addItem(starItem);
                    if (rechargeableItems.contains(Integer.valueOf(starItem.getItemId()))) {
                        recharges.remove(Integer.valueOf(starItem.getItemId()));
                    }
                } else {
                    ret.addItem(new MapleShopItem((short) rs.getShort("buyable"), rs.getShort("quantity"), rs.getInt("itemid"), rs.getInt("price"), (short) rs.getInt("position"), rs.getInt("reqitem"), rs.getInt("reqitemq"), rs.getByte("rank"), rs.getInt("category"), rs.getInt("minLevel"), rs.getInt("expiration"), false)); //todo potential
                }
            }
        }
        for (Integer recharge : recharges) {
            ret.addItem(new MapleShopItem((short) 1, ii.getSlotMax(recharge.intValue()), recharge.intValue(), 0, (short) 0, 0, 0, (byte) 0, 0, 0, 0, false));
        }
        rs.close();
        ps.close();

        ps = con.prepareStatement("SELECT * FROM shopranks WHERE shopid = ? ORDER BY rank ASC");
        ps.setInt(1, shopId);
        rs = ps.executeQuery();
        while (rs.next()) {
            if (ii.itemExists(rs.getInt("itemid"))) {
                ret.ranks.add(new Pair<Integer, String>(Integer.valueOf(rs.getInt("itemid")), rs.getString("name")));
            }
        }
        rs.close();
        ps.close();
    } catch (SQLException e) {
        System.err.println("Could not load shop");
    }
    return ret;
}