List of usage examples for java.sql ResultSet getBytes
byte[] getBytes(String columnLabel) throws SQLException;
ResultSet
object as a byte
array in the Java programming language. From source file:org.apache.hadoop.hive.druid.TestDruidStorageHandler.java
private List<DataSegment> getUsedSegmentsList(DerbyConnectorTestUtility connector, final MetadataStorageTablesConfig metadataStorageTablesConfig) { return connector.getDBI().withHandle(new HandleCallback<List<DataSegment>>() { @Override// w ww .j a va 2s . c o m public List<DataSegment> withHandle(Handle handle) throws Exception { return handle .createQuery( String.format("SELECT payload FROM %s WHERE used=true ORDER BY created_date ASC", metadataStorageTablesConfig.getSegmentsTable())) .map(new ResultSetMapper<DataSegment>() { @Override public DataSegment map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException { try { return DruidStorageHandlerUtils.JSON_MAPPER .readValue(resultSet.getBytes("payload"), DataSegment.class); } catch (IOException e) { throw Throwables.propagate(e); } } }).list(); } }); }
From source file:org.quartz.impl.jdbcjobstore.PointbaseDelegate.java
/** * <p>/*from ww w. j a v a 2 s. c o m*/ * This method should be overridden by any delegate subclasses that need * special handling for BLOBs. The default implementation uses standard * JDBC <code>java.sql.Blob</code> operations. * </p> * * @param rs * the result set, already queued to the correct row * @param colName * the column name for the BLOB * @return the deserialized Object from the ResultSet BLOB * @throws ClassNotFoundException * if a class found during deserialization cannot be found * @throws IOException * if deserialization causes an error */ protected Object getObjectFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { //log.debug( "Getting blob from column: " + colName ); Object obj = null; byte binaryData[] = rs.getBytes(colName); InputStream binaryInput = new ByteArrayInputStream(binaryData); if (null != binaryInput && binaryInput.available() != 0) { ObjectInputStream in = new ObjectInputStream(binaryInput); try { obj = in.readObject(); } finally { in.close(); } } return obj; }
From source file:com.chaosinmotion.securechat.server.commands.GetMessages.java
public static ReturnResult processRequest(Login.UserInfo userinfo, JSONObject requestParams) throws ClassNotFoundException, SQLException, IOException { String deviceid = requestParams.optString("deviceid"); MessageReturnResult mrr = new MessageReturnResult(); /*//from ww w . j a v a 2s . co m * Save message to the database. */ Connection c = null; PreparedStatement ps = null; ResultSet rs = null; try { /* * Get the device ID for this device. Verify it belongs to the * user specified */ c = Database.get(); ps = c.prepareStatement("SELECT deviceid " + "FROM Devices " + "WHERE deviceuuid = ? AND userid = ?"); ps.setString(1, deviceid); ps.setInt(2, userinfo.getUserID()); rs = ps.executeQuery(); int deviceID = 0; if (rs.next()) { deviceID = rs.getInt(1); } rs.close(); ps.close(); if (deviceID == 0) { return new ReturnResult(Errors.ERROR_UNKNOWNDEVICE, "Unknown device"); } /* * Run query to get messages */ ps = c.prepareStatement("SELECT Messages.messageid, " + " Messages.senderid, " + " Users.username, " + " Messages.toflag, " + " Messages.received, " + " Messages.message " + "FROM Messages, Users " + "WHERE Messages.deviceid = ? " + " AND Messages.senderid = Users.userid"); ps.setInt(1, deviceID); rs = ps.executeQuery(); while (rs.next()) { int messageID = rs.getInt(1); int senderID = rs.getInt(2); String senderName = rs.getString(3); boolean toflag = rs.getBoolean(4); Timestamp received = rs.getTimestamp(5); byte[] message = rs.getBytes(6); mrr.addMessage(messageID, senderID, senderName, toflag, received, message); } /* * Return messages */ return mrr; } finally { if (rs != null) rs.close(); if (ps != null) ps.close(); if (c != null) c.close(); } }
From source file:org.wso2.carbon.device.mgt.core.dao.impl.AbstractApplicationDAOImpl.java
private Application loadApplication(ResultSet rs) throws DeviceManagementDAOException { ByteArrayInputStream bais;//from w w w. ja va 2s. c o m ObjectInputStream ois; Properties properties; Application application = new Application(); try { application.setId(rs.getInt("ID")); application.setName(rs.getString("NAME")); application.setType(rs.getString("TYPE")); if (rs.getBytes("APP_PROPERTIES") != null) { byte[] appProperties = rs.getBytes("APP_PROPERTIES"); bais = new ByteArrayInputStream(appProperties); ois = new ObjectInputStream(bais); properties = (Properties) ois.readObject(); application.setAppProperties(properties); } application.setCategory(rs.getString("CATEGORY")); application.setImageUrl(rs.getString("IMAGE_URL")); application.setLocationUrl(rs.getString("LOCATION_URL")); application.setPlatform(rs.getString("PLATFORM")); application.setVersion(rs.getString("VERSION")); application.setMemoryUsage(rs.getInt("MEMORY_USAGE")); application.setActive(rs.getBoolean("IS_ACTIVE")); application.setApplicationIdentifier(rs.getString("APP_IDENTIFIER")); } catch (IOException e) { throw new DeviceManagementDAOException("IO error occurred fetch at app properties", e); } catch (ClassNotFoundException e) { throw new DeviceManagementDAOException("Class not found error occurred fetch at app properties", e); } catch (SQLException e) { throw new DeviceManagementDAOException("SQL error occurred fetch at application", e); } return application; }
From source file:org.apache.synapse.message.store.impl.resequencer.ResequenceMessageStore.java
/** * <p>/*from ww w. j av a2s .c om*/ * Gets message with minimum sequence id. * </p> * * @param resultSet the results returned from the query. * @param statement statement which is executed to obtain the results. * @return message which has the minimum sequence id. * @throws SQLException if an error is returned from the db while obtaining the sequence id value. */ private List<Map> getMessageWithMinimumId(ResultSet resultSet, String statement) throws SQLException { ArrayList<Map> elements = new ArrayList<>(); while (resultSet.next()) { try { HashMap<String, Object> rowData = new HashMap<>(); byte[] msgObj = resultSet.getBytes(MESSAGE_COLUMN_NAME); MessageContext responseMessageContext = deserializeMessage(msgObj); rowData.put(MESSAGE_COLUMN_NAME, responseMessageContext); long sequenceId = resultSet.getLong(ResequenceMessageStoreConstants.SEQUENCE_ID_COLUMN); rowData.put(ResequenceMessageStoreConstants.SEQUENCE_ID_COLUMN, sequenceId); elements.add(rowData); } catch (SQLException e) { String message = "Error executing statement : " + statement + " against " + "DataSource : " + getJdbcConfiguration().getDSName(); throw new SynapseException(message, e); } } return elements; }
From source file:org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.ConfigOperationDAOImpl.java
@Override public Operation getOperation(int operationId) throws OperationManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; ConfigOperation configOperation = null; ByteArrayInputStream bais;//from ww w.jav a 2s . co m ObjectInputStream ois; try { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT OPERATION_ID, ENABLED, OPERATION_CONFIG FROM DM_CONFIG_OPERATION WHERE OPERATION_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, operationId); rs = stmt.executeQuery(); if (rs.next()) { byte[] operationDetails = rs.getBytes("OPERATION_CONFIG"); bais = new ByteArrayInputStream(operationDetails); ois = new ObjectInputStream(bais); configOperation = (ConfigOperation) ois.readObject(); configOperation.setId(rs.getInt("OPERATION_ID")); configOperation.setEnabled(rs.getBoolean("ENABLED")); } } catch (IOException e) { throw new OperationManagementDAOException( "IO Error occurred while de serialize the policy operation " + "object", e); } catch (ClassNotFoundException e) { throw new OperationManagementDAOException( "Class not found error occurred while de serialize the policy " + "operation object", e); } catch (SQLException e) { throw new OperationManagementDAOException("SQL Error occurred while retrieving the policy operation " + "object available for the id '" + operationId, e); } finally { OperationManagementDAOUtil.cleanupResources(stmt, rs); } return configOperation; }
From source file:org.panbox.core.keymgmt.JDBCHelperNonRevokeable.java
protected byte[] getDeviceListSignature(Connection con) throws SQLException, SignatureException { PreparedStatement s = con.prepareStatement(QUERY_SIGNATURE); ResultSet rs = s.executeQuery(); if (rs.next()) { byte[] result = rs.getBytes(COL_SIGNATURE); if (rs.next()) { logger.error("More than one device list signature found"); throw new SignatureException("More than one device list signature found"); }/* w w w. j av a2s . c o m*/ rs.close(); s.close(); return result; } else { rs.close(); s.close(); // throw new // SignatureException("No signature found for device list"); return null; } }
From source file:org.quartz.impl.jdbcjobstore.PointbaseDelegate.java
/** * <p>/*from w ww . ja va 2 s . co m*/ * This method should be overridden by any delegate subclasses that need * special handling for BLOBs for job details. The default implementation * uses standard JDBC <code>java.sql.Blob</code> operations. * </p> * * @param rs * the result set, already queued to the correct row * @param colName * the column name for the BLOB * @return the deserialized Object from the ResultSet BLOB * @throws ClassNotFoundException * if a class found during deserialization cannot be found * @throws IOException * if deserialization causes an error */ protected Object getJobDetailFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { //log.debug( "Getting Job details from blob in col " + colName ); if (canUseProperties()) { byte data[] = rs.getBytes(colName); if (data == null) { return null; } InputStream binaryInput = new ByteArrayInputStream(data); return binaryInput; } return getObjectFromBlob(rs, colName); }
From source file:org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.ProfileOperationDAOImpl.java
public Operation getOperation(int id) throws OperationManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; ProfileOperation profileOperation = null; ByteArrayInputStream bais;//from ww w .j ava2 s .c o m ObjectInputStream ois; try { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT OPERATION_ID, ENABLED, OPERATION_DETAILS FROM DM_PROFILE_OPERATION WHERE OPERATION_ID=?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, id); rs = stmt.executeQuery(); if (rs.next()) { byte[] operationDetails = rs.getBytes("OPERATION_DETAILS"); bais = new ByteArrayInputStream(operationDetails); ois = new ObjectInputStream(bais); profileOperation = (ProfileOperation) ois.readObject(); } } catch (IOException e) { throw new OperationManagementDAOException( "IO Error occurred while de serialize the profile " + "operation object", e); } catch (ClassNotFoundException e) { throw new OperationManagementDAOException( "Class not found error occurred while de serialize the " + "profile operation object", e); } catch (SQLException e) { throw new OperationManagementDAOException("SQL Error occurred while retrieving the command " + "operation object " + "available for the id '" + id, e); } finally { OperationManagementDAOUtil.cleanupResources(stmt, rs); } return profileOperation; }
From source file:org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.PolicyOperationDAOImpl.java
@Override public Operation getOperation(int operationId) throws OperationManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; PolicyOperation policyOperation = null; ByteArrayInputStream bais;/*from w w w . j a va 2 s .c om*/ ObjectInputStream ois; try { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT OPERATION_ID, ENABLED, OPERATION_DETAILS FROM DM_POLICY_OPERATION WHERE OPERATION_ID=?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, operationId); rs = stmt.executeQuery(); if (rs.next()) { byte[] operationDetails = rs.getBytes("OPERATION_DETAILS"); bais = new ByteArrayInputStream(operationDetails); ois = new ObjectInputStream(bais); policyOperation = (PolicyOperation) ois.readObject(); } } catch (IOException e) { throw new OperationManagementDAOException( "IO Error occurred while de serialize the policy operation " + "object", e); } catch (ClassNotFoundException e) { throw new OperationManagementDAOException( "Class not found error occurred while de serialize the " + "policy operation object", e); } catch (SQLException e) { throw new OperationManagementDAOException("SQL Error occurred while retrieving the policy operation " + "object available for the id '" + operationId + "'", e); } finally { OperationManagementDAOUtil.cleanupResources(stmt, rs); } return policyOperation; }