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:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMySql.CFAccMySqlSchema.java
public static Byte getNullableByte(ResultSet reader, int colidx) { try {//from ww w .ja va 2 s . c o m byte val = reader.getByte(colidx); if (reader.wasNull()) { return (null); } else { return (new Byte(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAccMySqlSchema.class, "getNullableByte", e); } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java
public static Byte getNullableByte(ResultSet reader, int colidx) { try {/*from www . j a va 2 s. c o m*/ byte val = reader.getByte(colidx); if (reader.wasNull()) { return (null); } else { return (new Byte(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAccMSSqlSchema.class, "getNullableByte", e); } }
From source file:org.ojbc.intermediaries.sn.dao.TestSubscriptionSearchQueryDAO.java
@Test @DirtiesContext// w w w.j a va2 s.c om public void testUnsubscribeBySystemId() throws Exception { loadBasicTestData(); Statement s = dataSource.getConnection().createStatement(); ResultSet rs = s.executeQuery("select * from subscription"); assertTrue(rs.next()); int id = rs.getInt("id"); byte active = rs.getByte("ACTIVE"); String topic = rs.getString("topic"); assertEquals(1, active); subscriptionSearchQueryDAO.unsubscribe("" + id, topic, null, null, null); rs = s.executeQuery("select * from subscription where id=" + id); assertTrue(rs.next()); active = rs.getByte("ACTIVE"); assertEquals(0, active); }
From source file:com.linkage.community.schedule.dbutils.CustomScalarHandler.java
/** * Returns one <code>ResultSet</code> column as an object via the * <code>ResultSet.getObject()</code> method that performs type * conversions./* w w w .j ava 2 s .c o m*/ * @param rs <code>ResultSet</code> to process. * @return The column or <code>null</code> if there are no rows in * the <code>ResultSet</code>. * * @throws SQLException if a database access error occurs * @throws ClassCastException if the class datatype does not match the column type * * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet) */ // We assume that the user has picked the correct type to match the column // so getObject will return the appropriate type and the cast will succeed. @SuppressWarnings("unchecked") //@Override public T handle(ResultSet rs) throws SQLException { Object obj = null; if (rs.next()) { if (this.columnName == null) { obj = rs.getObject(this.columnIndex); if (obj instanceof Integer) return (T) (obj = rs.getInt(columnIndex)); else if (obj instanceof Long) return (T) (obj = (new Long(rs.getLong(columnIndex)).intValue())); else if (obj instanceof Boolean) return (T) (obj = rs.getBoolean(columnIndex)); else if (obj instanceof Double) return (T) (obj = rs.getDouble(columnIndex)); else if (obj instanceof Float) return (T) (obj = rs.getFloat(columnIndex)); else if (obj instanceof Short) return (T) (obj = rs.getShort(columnIndex)); else if (obj instanceof Byte) return (T) (obj = rs.getByte(columnIndex)); else return (T) obj; } else { obj = rs.getObject(this.columnName); if (obj instanceof Integer) return (T) (obj = rs.getInt(columnName)); else if (obj instanceof Long) return (T) (obj = rs.getLong(columnName)); else if (obj instanceof Boolean) return (T) (obj = rs.getBoolean(columnName)); else if (obj instanceof Double) return (T) (obj = rs.getDouble(columnName)); else if (obj instanceof Float) return (T) (obj = rs.getFloat(columnName)); else if (obj instanceof Short) return (T) (obj = rs.getShort(columnName)); else if (obj instanceof Byte) return (T) (obj = rs.getByte(columnName)); else return (T) obj; } } return null; }
From source file:org.ojbc.intermediaries.sn.dao.TestSubscriptionSearchQueryDAO.java
@Test @DirtiesContext//w w w. j av a 2s . co m public void testUnsubscribeBySubject() throws Exception { loadBasicTestData(); Statement s = dataSource.getConnection().createStatement(); ResultSet rs = s.executeQuery("select * from subscription where active=1"); assertTrue(rs.next()); int id = rs.getInt("id"); byte active = rs.getByte("ACTIVE"); String topic = rs.getString("topic"); String systemName = rs.getString("subscribingSystemIdentifier"); String owner = rs.getString("subscriptionOwner"); assertEquals(1, active); rs.close(); rs = s.executeQuery("select * from subscription_subject_identifier where subscriptionid=" + id); Map<String, String> subjectIdMap = new HashMap<String, String>(); while (rs.next()) { subjectIdMap.put(rs.getString("IdentifierName"), rs.getString("IdentifierValue")); } subscriptionSearchQueryDAO.unsubscribe(null, topic, subjectIdMap, systemName, owner); rs = s.executeQuery("select * from subscription where id=" + id); assertTrue(rs.next()); active = rs.getByte("ACTIVE"); assertEquals(0, active); s.close(); }
From source file:com.flexive.ejb.beans.ACLEngineBean.java
/** * {@inheritDoc}//from w w w . j a va2 s.co m */ @Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public List<ACLAssignment> loadAssignments(Long aclId, Long groupId) throws FxApplicationException { Connection con = null; Statement stmt = null; String curSql; UserTicket ticket = FxContext.getUserTicket(); // Permission & Exists check checkPermissions(ticket, groupId, aclId, false); try { // Obtain a database connection con = Database.getDbConnection(); // load assignments // 1 2 3 4 5 6 7 curSql = "SELECT ass.USERGROUP,ass.ACL,ass.PREAD,ass.PEDIT,ass.PREMOVE,ass.PEXPORT,ass.PREL," + // 8 , 9 10 11 12 13 "ass.PCREATE,acl.CAT_TYPE,ass.CREATED_BY,ass.CREATED_AT,ass.MODIFIED_BY,ass.MODIFIED_AT " + "FROM " + TBL_ACLS_ASSIGNMENT + " ass, " + TBL_ACLS + " acl WHERE " + "ass.ACL=acl.ID AND " + ((groupId != null) ? "USERGROUP=" + groupId : "") + ((groupId != null && aclId != null) ? " AND " : "") + ((aclId != null) ? "ACL=" + aclId : ""); stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(curSql); // Read the data ArrayList<ACLAssignment> result = new ArrayList<ACLAssignment>(20); while (rs != null && rs.next()) result.add(new ACLAssignment(rs.getLong(2), rs.getLong(1), rs.getBoolean(3), rs.getBoolean(4), rs.getBoolean(7), rs.getBoolean(5), rs.getBoolean(6), rs.getBoolean(8), ACLCategory.getById(rs.getByte(9)), LifeCycleInfoImpl.load(rs, 10, 11, 12, 13))); // Return the found entries result.trimToSize(); return result; } catch (SQLException exc) { throw new FxLoadException(LOG, exc, "ex.aclAssignment.loadFailed"); } finally { Database.closeObjects(ACLEngineBean.class, con, stmt); } }
From source file:org.apache.hadoop.hive.jdbc.TestJdbcDriver.java
private void assertPreparedStatementResultAsExpected(ResultSet res) throws SQLException { assertNotNull(res);//w ww . ja v a 2s .c o m while (res.next()) { assertEquals("2011-03-25", res.getString("ddate")); assertEquals("10", res.getString("num")); assertEquals((byte) 10, res.getByte("num")); assertEquals("2011-03-25", res.getDate("ddate").toString()); assertEquals(Double.valueOf(10).doubleValue(), res.getDouble("num"), 0.1); assertEquals(10, res.getInt("num")); assertEquals(Short.valueOf("10").shortValue(), res.getShort("num")); assertEquals(10L, res.getLong("num")); assertEquals(true, res.getBoolean("bv")); Object o = res.getObject("ddate"); assertNotNull(o); o = res.getObject("num"); assertNotNull(o); } res.close(); assertTrue(true); }
From source file:io.hops.metadata.ndb.dalimpl.hdfs.EncodingStatusClusterj.java
private List<EncodingStatus> find(String query) throws StorageException { ArrayList<EncodingStatus> resultList; try {/*from ww w.j av a2 s . co m*/ Connection conn = mysqlConnector.obtainSession(); PreparedStatement s = conn.prepareStatement(query); ResultSet result = s.executeQuery(); resultList = new ArrayList<EncodingStatus>(); while (result.next()) { Integer inodeId = result.getInt(INODE_ID); Integer parityInodeId = result.getInt(PARITY_INODE_ID); Integer status = result.getInt(STATUS); String codec = result.getString(CODEC); Short targetReplication = result.getShort(TARGET_REPLICATION); Long statusModificationTime = result.getLong(STATUS_MODIFICATION_TIME); Integer parityStatus = result.getInt(PARITY_STATUS); Long parityStatusModificationTime = result.getLong(PARITY_STATUS_MODIFICATION_TIME); String parityFileName = result.getString(PARITY_FILE_NAME); int lostBlocks = result.getInt(LOST_BLOCKS); int lostParityBlocks = result.getInt(LOST_PARITY_BLOCKS); Boolean revoked = NdbBoolean.convert(result.getByte(REVOKED)); EncodingPolicy policy = new EncodingPolicy(codec, targetReplication); resultList.add(new EncodingStatus(inodeId, parityInodeId, EncodingStatus.Status.values()[status], EncodingStatus.ParityStatus.values()[parityStatus], policy, statusModificationTime, parityStatusModificationTime, parityFileName, lostBlocks, lostParityBlocks, revoked)); } } catch (SQLException ex) { throw HopsSQLExceptionHelper.wrap(ex); } finally { mysqlConnector.closeSession(); } return resultList; }
From source file:edu.ku.brc.specify.ui.db.ResultSetTableModel.java
/** * @param setter//from ww w .j a v a 2s . c o m * @param parent * @param fieldName * @param fieldClass * @param resultSet * @param colIndex * @throws SQLException */ protected void setField(final DataObjectSettable setter, final Object parent, final String fieldName, final Class<?> fieldClass, final ResultSet resultSet, final int colIndex) throws SQLException { Object fieldDataObj = resultSet.getObject(colIndex + 1); //log.debug("fieldName ["+fieldName+"] fieldClass ["+fieldClass.getSimpleName()+"] colIndex [" + colIndex + "] fieldDataObj [" + fieldDataObj+"]"); if (fieldDataObj != null) { if (fieldClass == String.class) { setter.setFieldValue(parent, fieldName, fieldDataObj); } else if (fieldClass == Byte.class) { setter.setFieldValue(parent, fieldName, resultSet.getByte(colIndex + 1)); } else if (fieldClass == Short.class) { setter.setFieldValue(parent, fieldName, resultSet.getShort(colIndex + 1)); } else { setter.setFieldValue(parent, fieldName, fieldDataObj); } } }
From source file:org.sleuthkit.autopsy.timeline.events.db.EventDB.java
private TimeLineEvent constructTimeLineEvent(ResultSet rs) throws SQLException { EventType type = RootEventType.allTypes.get(rs.getInt(SUB_TYPE_COLUMN)); return new TimeLineEvent(rs.getLong(EVENT_ID_COLUMN), rs.getLong(FILE_ID_COLUMN), rs.getLong(ARTIFACT_ID_COLUMN), rs.getLong(TIME_COLUMN), type, rs.getString(FULL_DESCRIPTION_COLUMN), rs.getString(MED_DESCRIPTION_COLUMN), rs.getString(SHORT_DESCRIPTION_COLUMN), TskData.FileKnown.valueOf(rs.getByte(KNOWN_COLUMN))); }