List of usage examples for java.sql ResultSet getBlob
Blob getBlob(String columnLabel) throws SQLException;
ResultSet
object as a Blob
object in the Java programming language. From source file:modelo.ProcesoVertimientosManagers.ProgramarMonitoreo.java
public ArchivoExtension getArchivosCargado(Integer codigoArchivo, int codigoMonitoreo) throws SQLException { SeleccionarArchivosCargadosSupervision select = new SeleccionarArchivosCargadosSupervision(); ResultSet rset = select.getArchivosCargados(codigoArchivo, codigoMonitoreo); String nombreArchivo = null;/*from www.j av a2s . c om*/ Blob dataArchivo = null; ArchivoExtension archivo; while (rset.next()) { nombreArchivo = rset.getString("NOMBRE_ARCHIVO"); dataArchivo = rset.getBlob("ARCHIVO"); } archivo = new ArchivoExtension(dataArchivo, nombreArchivo); return archivo; }
From source file:com.sun.licenseserver.License.java
/** * Retrieve a license from the database that belongs to the given * userID, contentID and shopID combination. * /* w w w. j av a 2 s .co m*/ * @param userID * @param contentID * @param shopID * @return * @throws LicenseServerException */ public static License getLicenseFromDatabase(String userID, String contentID, String shopID) throws LicenseServerException { m_log.finer("Entering Function.."); m_log.fine("Find license for user=[" + userID + "]contentID=[" + contentID + "]shopID=[" + shopID + "]"); ResultSet rs = null; License lic = null; Blob license = null; String id = ""; String mime = ""; String expression = "select license, id, mime from sunLsLicenses where contentId= '" + contentID + "' and shopId='" + shopID + "' and userId='" + userID + "'"; DatabaseHelper dbh = DatabaseHelper.getDatabaseHelper(); rs = dbh.executeStatementWithResults(expression); // The check below is not working. // We need to invoke the beforeFirst() function on the // result set after we have counted the number of entries in the result set. // The beforeFirst() method does not works and throws an exception. // A work around has to be found to reinstate this test. // // if (dbh.countNumberInResultSet(rs) > 1) { // m_log.severe("More than one license retrieved for a given userID, contentID and shopID combo"); // throw new LicenseServerException(LicenseServerException.EC_NO_ERROR_CODE, // "More than one license retrieved for a given userID, contentID and shopID combo"); // } try { if (rs != null && rs.next()) { ; license = rs.getBlob("license"); id = rs.getObject("id").toString(); mime = rs.getObject("mime").toString(); id = id == null ? "" : id; mime = mime == null ? "" : mime; lic = new License(id, userID, contentID, shopID, mime, license.getBinaryStream()); } dbh.releaseResultSetResources(rs); } catch (SQLException e) { m_log.severe("Error in retrieveing license from result set"); e.printStackTrace(); throw new LicenseServerException(LicenseServerException.EC_NO_ERROR_CODE, "Error in retrieveing license from result set"); } m_log.finer("Leaving Function.."); return lic; }
From source file:org.wso2.carbon.das.jobmanager.core.impl.RDBMSServiceImpl.java
public ResourcePool getResourcePool(String groupId) throws ResourceManagerException { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; ResourcePool resourcePool = null;/*from w w w. jav a 2 s . c o m*/ try { connection = getConnection(); preparedStatement = connection .prepareStatement(ResourceManagerConstants.PS_SELECT_RESOURCE_MAPPING_ROW); preparedStatement.setString(1, groupId); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { Blob blob = resultSet.getBlob(2); if (blob != null) { int blobLength = (int) blob.length(); byte[] bytes = blob.getBytes(1, blobLength); ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); Object blobObject = ois.readObject(); if (blobObject instanceof ResourcePool) { resourcePool = (ResourcePool) blobObject; } } } connection.commit(); } catch (SQLException | ClassNotFoundException | IOException e) { throw new ResourceManagerException( "Error occurred while " + ResourceManagerConstants.TASK_GET_RESOURCE_MAPPING, e); } finally { close(resultSet, ResourceManagerConstants.TASK_GET_RESOURCE_MAPPING); close(preparedStatement, ResourceManagerConstants.TASK_GET_RESOURCE_MAPPING); close(connection, ResourceManagerConstants.TASK_GET_RESOURCE_MAPPING); } return resourcePool; }
From source file:eionet.cr.dao.readers.StagingDatabaseDTOReader.java
@Override public void readRow(ResultSet rs) throws SQLException, ResultSetReaderException { StagingDatabaseDTO databaseDTO = new StagingDatabaseDTO(); databaseDTO.setId(rs.getInt("DATABASE_ID")); databaseDTO.setName(rs.getString("NAME")); databaseDTO.setCreator(rs.getString("CREATOR")); databaseDTO.setCreated(rs.getTimestamp("CREATED")); databaseDTO.setDescription(rs.getString("DESCRIPTION")); databaseDTO.setImportStatus(Enum.valueOf(ImportStatus.class, rs.getString("IMPORT_STATUS"))); databaseDTO.setImportLog(rs.getString("IMPORT_LOG")); try {/* w ww . j a va2 s. c o m*/ Blob blob = rs.getBlob("DEFAULT_QUERY"); String query = blob == null ? null : blob.length() == 0 ? "" : IOUtils.toString(blob.getBinaryStream()); databaseDTO.setDefaultQuery(query); } catch (Exception e) { LOGGER.warn("Failed to read column: DEFAULT_QUERY", e); } resultList.add(databaseDTO); }
From source file:nz.co.gregs.dbvolution.datatypes.DBByteArray.java
private byte[] getFromBLOB(ResultSet resultSet, String fullColumnName) throws SQLException { byte[] bytes = new byte[] {}; Blob blob = resultSet.getBlob(fullColumnName); if (resultSet.wasNull()) { blob = null;//from w ww.ja v a 2 s .co m } if (blob == null) { this.setToNull(); } else { InputStream inputStream = blob.getBinaryStream(); bytes = getBytesFromInputStream(inputStream); } return bytes; }
From source file:org.quartz.impl.jdbcjobstore.oracle.OracleDelegate.java
protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data) throws SQLException { Blob blob = rs.getBlob(column); // get blob if (blob == null) { throw new SQLException("Driver's Blob representation is null!"); }// ww w. j a v a 2s .co m if (blob instanceof oracle.sql.BLOB) { // is it an oracle blob? ((oracle.sql.BLOB) blob).putBytes(1, data); return blob; } else { throw new SQLException( "Driver's Blob representation is of an unsupported type: " + blob.getClass().getName()); } }
From source file:org.springframework.jdbc.support.lob.OracleLobHandler.java
@Override public byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException { logger.debug("Returning Oracle BLOB as bytes"); Blob blob = rs.getBlob(columnIndex); initializeResourcesBeforeRead(rs.getStatement().getConnection(), blob); byte[] retVal = (blob != null ? blob.getBytes(1, (int) blob.length()) : null); releaseResourcesAfterRead(rs.getStatement().getConnection(), blob); return retVal; }
From source file:org.springframework.jdbc.support.lob.OracleLobHandler.java
@Override public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException { logger.debug("Returning Oracle BLOB as binary stream"); Blob blob = rs.getBlob(columnIndex); initializeResourcesBeforeRead(rs.getStatement().getConnection(), blob); InputStream retVal = (blob != null ? blob.getBinaryStream() : null); releaseResourcesAfterRead(rs.getStatement().getConnection(), blob); return retVal; }
From source file:com.micromux.cassandra.jdbc.JdbcRegressionTest.java
@Test public void testBlob() throws Exception { UUID blobId = UUID.randomUUID(); CassandraBlob blobValue = new CassandraBlob(RandomStringUtils.random(10)); String insert = "INSERT INTO " + TYPETABLE + " (id,blobValue,dataMapValue) " + " VALUES(" + blobId.toString() + ", ?, {'12345': bigintAsBlob(12345)});"; PreparedStatement statement = con.prepareStatement(insert); statement.setBlob(1, blobValue);// w ww . j av a2s . co m statement.executeUpdate(); statement.close(); Statement select1 = con.createStatement(); String query = "SELECT blobValue FROM " + TYPETABLE + " WHERE id=" + blobId.toString() + ";"; ResultSet result = select1.executeQuery(query); result.next(); Blob blobResult = result.getBlob(1); assertEquals(blobValue, blobResult); Statement select2 = con.createStatement(); String query2 = "SELECT dataMapValue FROM " + TYPETABLE + " WHERE id=" + blobId.toString() + ";"; ResultSet result2 = select2.executeQuery(query2); result2.next(); Object mapResult = result2.getObject(1); assertTrue(mapResult instanceof Map); assertEquals("There should be 1 record in the map", 1, ((Map) mapResult).size()); assertNotNull("Entry for '12345' should be in the map", ((Map) mapResult).get("12345")); assertNull("Entry for '54321' should NOT be in the map", ((Map) mapResult).get("54321")); }
From source file:org.georepublic.db.utils.ResultSetConverter.java
public static StringBuffer convertCsv(ResultSet rs) throws SQLException { String column_name = new String(); StringBuffer retval = new StringBuffer(); ResultSetMetaData rsmd = rs.getMetaData(); int numColumns = rsmd.getColumnCount(); for (int h = 1; h < numColumns + 1; h++) { column_name = rsmd.getColumnName(h); if (h > 1) { retval.append(","); }/* w w w . ja v a2 s . c om*/ retval.append(column_name); } retval.append("\n"); while (rs.next()) { for (int i = 1; i < numColumns + 1; i++) { column_name = rsmd.getColumnName(i); if (StringUtils.equals(column_name, "the_geom")) { continue; } if (StringUtils.equals(column_name, "geojson")) { continue; } if (i > 1) { retval.append(","); } if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) { retval.append(rs.getArray(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) { retval.append(rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) { retval.append(rs.getBoolean(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BLOB) { retval.append(rs.getBlob(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) { retval.append(rs.getDouble(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) { retval.append(rs.getFloat(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) { retval.append(rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) { retval.append(rs.getNString(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.VARCHAR) { retval.append(rs.getString(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) { retval.append(rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) { retval.append(rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) { retval.append(rs.getDate(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) { retval.append(rs.getTimestamp(column_name)); } else { retval.append(rs.getObject(column_name)); } } retval.append("\n"); } return retval; }