List of usage examples for java.sql ResultSet getByte
byte getByte(String columnLabel) throws SQLException;
ResultSet
object as a byte
in the Java programming language. From source file:org.waarp.common.database.data.AbstractDbData.java
/** * Get one value into DbValue from ResultSet * //from ww w.ja v a2s. c o m * @param rs * @param value * @throws WaarpDatabaseSqlException */ static public void getTrueValue(ResultSet rs, DbValue value) throws WaarpDatabaseSqlException { try { switch (value.type) { case Types.VARCHAR: value.value = rs.getString(value.column); break; case Types.LONGVARCHAR: value.value = rs.getString(value.column); break; case Types.BIT: value.value = rs.getBoolean(value.column); break; case Types.TINYINT: value.value = rs.getByte(value.column); break; case Types.SMALLINT: value.value = rs.getShort(value.column); break; case Types.INTEGER: value.value = rs.getInt(value.column); break; case Types.BIGINT: value.value = rs.getLong(value.column); break; case Types.REAL: value.value = rs.getFloat(value.column); break; case Types.DOUBLE: value.value = rs.getDouble(value.column); break; case Types.VARBINARY: value.value = rs.getBytes(value.column); break; case Types.DATE: value.value = rs.getDate(value.column); break; case Types.TIMESTAMP: value.value = rs.getTimestamp(value.column); break; case Types.CLOB: value.value = rs.getClob(value.column).getCharacterStream(); break; case Types.BLOB: value.value = rs.getBlob(value.column).getBinaryStream(); break; default: throw new WaarpDatabaseSqlException("Type not supported: " + value.type + " for " + value.column); } } catch (SQLException e) { DbSession.error(e); throw new WaarpDatabaseSqlException("Getting values in error: " + value.type + " for " + value.column, e); } }
From source file:net.sourceforge.msscodefactory.cfinternet.v2_0.CFInternetXMsgClient.CFInternetXMsgClientSchema.java
public static Byte getNullableByte(ResultSet reader, int colidx) { try {/* w ww. ja va 2s .com*/ byte val = reader.getByte(colidx); if (reader.wasNull()) { return (null); } else { return (new Byte(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFInternetXMsgClientSchema.class, "getNullableByte", e); } }
From source file:com.l2jfree.gameserver.model.entity.hellbound.TowerOfNaiaRoom.java
public void initDoors(final int roomId) { Connection con = null;//w w w.ja v a 2 s. c om try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement("SELECT * FROM hb_naia_doorlist WHERE room_id=?"); statement.setInt(1, roomId); ResultSet rset = statement.executeQuery(); while (rset.next()) { int doorId = rset.getInt("door_id"); byte action = rset.getByte("action_order"); switch (action) { case 0: _preOpenDoorIds = ArrayUtils.add(_preOpenDoorIds, doorId); break; case 1: _preCloseDoorIds = ArrayUtils.add(_preOpenDoorIds, doorId); break; case 2: _postOpenDoorIds = ArrayUtils.add(_preOpenDoorIds, doorId); break; case 3: _postCloseDoorIds = ArrayUtils.add(_preOpenDoorIds, doorId); break; } } rset.close(); statement.close(); } catch (Exception e) { _log.warn("TowerOfNaia: Door could not be initialized: ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:fr.in2p3.cc.storage.treqs.persistence.mysql.dao.MySQLConfigurationDAO.java
@Override public List<Resource> getMediaAllocations() throws TReqSException { LOGGER.trace("> getMediaAllocations"); final List<Resource> mediaTypeList = new ArrayList<Resource>(); final Object[] objects = MySQLBroker.getInstance().executeSelect(MySQLStatements.SQL_MEDIATYPES_SELECT); // store result final ResultSet result = (ResultSet) objects[1]; try {//from www.ja v a2 s . co m while (result.next()) { int index = 1; final byte id = result.getByte(index++); final String name = result.getString(index++); final short qty = result.getShort(index++); final String regExpId = result.getString(index++); final MediaType media = MediaTypesController.getInstance().add(name, id, regExpId); final Resource res = new Resource(media, qty); mediaTypeList.add(res); } } catch (final SQLException exception) { throw new MySQLExecuteException(exception); } finally { MySQLBroker.getInstance().terminateExecution(objects); } if (mediaTypeList.size() == 0) { // No entry in table, something wrong with configuration. LOGGER.warn("No drives (media type) found. Please define them " + "in the database."); } LOGGER.trace("< getMediaAllocations"); return mediaTypeList; }
From source file:fr.in2p3.cc.storage.treqs.persistence.mysql.dao.MySQLConfigurationDAO.java
@Override public MultiMap getResourceAllocation() throws TReqSException { LOGGER.trace("> getResourceAllocation"); // Allocations maps a media type to a pair (user,share) final MultiMap allocations = new MultiValueMap(); final Object[] objects = MySQLBroker.getInstance().executeSelect(MySQLStatements.SQL_ALLOCATIONS_SELECT); // Store result final ResultSet result = (ResultSet) objects[1]; try {//w w w.j a va2 s . c om while (result.next()) { int index = 1; final byte id = result.getByte(index++); final String userName = result.getString(index++); final float share = result.getFloat(index++); final PersistenceHelperResourceAllocation helper = new PersistenceHelperResourceAllocation(userName, share); allocations.put(new Byte(id), helper); LOGGER.debug("Allocation on mediatype: '" + id + "', user: '" + userName + "', share: " + share); } } catch (final SQLException exception) { throw new MySQLExecuteException(exception); } finally { MySQLBroker.getInstance().terminateExecution(objects); } if (allocations.size() == 0) { // No entry in table, something wrong with configuration. LOGGER.warn("No media type allocations found. Please define them " + "in the database."); } LOGGER.trace("< getResourceAllocation"); return allocations; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgClient.CFAstXMsgClientSchema.java
public static Byte getNullableByte(ResultSet reader, int colidx) { try {/*from w w w . ja va 2 s. c om*/ byte val = reader.getByte(colidx); if (reader.wasNull()) { return (null); } else { return (new Byte(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAstXMsgClientSchema.class, "getNullableByte", e); } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgClient.CFAccXMsgClientSchema.java
public static Byte getNullableByte(ResultSet reader, int colidx) { try {//from w w w. j a va 2s . c om byte val = reader.getByte(colidx); if (reader.wasNull()) { return (null); } else { return (new Byte(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAccXMsgClientSchema.class, "getNullableByte", e); } }
From source file:org.apache.cocoon.util.JDBCTypeConversions.java
/** * Get the Statement column so that the results are mapped correctly. * (this has been copied from AbstractDatabaseAction and modified slightly) *//*from ww w .j a va 2 s .com*/ public static Object getColumn(ResultSet set, Configuration column) throws Exception { Integer type = (Integer) JDBCTypeConversions.typeConstants.get(column.getAttribute("type")); String dbcol = column.getAttribute("name"); Object value = null; switch (type.intValue()) { case Types.CLOB: case Types.CHAR: Clob dbClob = set.getClob(dbcol); int length = (int) dbClob.length(); InputStream asciiStream = new BufferedInputStream(dbClob.getAsciiStream()); byte[] buffer = new byte[length]; asciiStream.read(buffer); String str = new String(buffer); asciiStream.close(); value = str; break; case Types.BIGINT: value = set.getBigDecimal(dbcol); break; case Types.TINYINT: value = new Byte(set.getByte(dbcol)); break; case Types.VARCHAR: value = set.getString(dbcol); break; case Types.DATE: value = set.getDate(dbcol); break; case Types.DOUBLE: value = new Double(set.getDouble(dbcol)); break; case Types.FLOAT: value = new Float(set.getFloat(dbcol)); break; case Types.INTEGER: value = new Integer(set.getInt(dbcol)); break; case Types.NUMERIC: value = new Long(set.getLong(dbcol)); break; case Types.SMALLINT: value = new Short(set.getShort(dbcol)); break; case Types.TIME: value = set.getTime(dbcol); break; case Types.TIMESTAMP: value = set.getTimestamp(dbcol); break; case Types.ARRAY: value = set.getArray(dbcol); // new Integer(set.getInt(dbcol)); break; case Types.BIT: value = BooleanUtils.toBooleanObject(set.getBoolean(dbcol)); break; case Types.STRUCT: value = (Struct) set.getObject(dbcol); break; case Types.OTHER: value = set.getObject(dbcol); break; default: // The blob types have to be requested separately, via a Reader. value = ""; break; } return value; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgClient.CFAsteriskXMsgClientSchema.java
public static Byte getNullableByte(ResultSet reader, int colidx) { try {//from www .j av a 2 s. co m byte val = reader.getByte(colidx); if (reader.wasNull()) { return (null); } else { return (new Byte(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAsteriskXMsgClientSchema.class, "getNullableByte", e); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8Schema.java
public static Byte getNullableByte(ResultSet reader, int colidx) { try {//from w w w.j ava2s . com byte val = reader.getByte(colidx); if (reader.wasNull()) { return (null); } else { return (new Byte(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(MSSBamPg8Schema.class, "getNullableByte", e); } }