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

The following are Jave code examples for showing how to use getBinaryStream() 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: all-file   File: SmartUpload.java   View Source Code Vote up 7 votes
public void fieldToFile(ResultSet resultset, String s, String s1)
    throws ServletException, IOException, SmartUploadException, SQLException
{
    try
    {
        if(m_application.getRealPath(s1) != null)
            s1 = m_application.getRealPath(s1);
        InputStream inputstream = resultset.getBinaryStream(s);
        FileOutputStream fileoutputstream = new FileOutputStream(s1);
        int i;
        while((i = inputstream.read()) != -1) 
            fileoutputstream.write(i);
        fileoutputstream.close();
    }
    catch(Exception exception)
    {
        throw new SmartUploadException("Unable to save file from the DataBase (1020).");
    }
}
 
Example 2
Project: lams   File: HSQLDBDelegate.java   View Source Code Vote up 7 votes
/**
 * <p>
 * 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
 */
@Override           
protected Object getObjectFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    InputStream binaryInput = rs.getBinaryStream(colName);

    if(binaryInput == null || binaryInput.available() == 0) {
        return null;
    }
    
    Object obj = null;
    
    ObjectInputStream in = new ObjectInputStream(binaryInput);
    try {
        obj = in.readObject();
    } finally {
        in.close();
    }

    return obj;
}
 
Example 3
Project: lams   File: OracleDelegate.java   View Source Code Vote up 7 votes
@Override
protected Object getObjectFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    
    Object obj = null;
    InputStream binaryInput = rs.getBinaryStream(colName);
    if (binaryInput != null) {
        ObjectInputStream in = new ObjectInputStream(binaryInput);
        try {
            obj = in.readObject();
        } finally {
            in.close();
        }
    }

    return obj;
}
 
Example 4
Project: drd   File: BaseDatabaseManager.java   View Source Code Vote up 7 votes
/**
 * Přešte blob dat ze zadaného sloupečku
 *
 * @param resultSet {@link ResultSet}
 * @param column Sloupeček, který obsahuje blob
 * @return Pole bytu
 * @throws SQLException
 * @throws IOException
 */
public static byte[] readBlob(ResultSet resultSet, String column) {
    final ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
    try {
        final InputStream binaryStream = resultSet.getBinaryStream(column);
        final byte[] buffer = new byte[1024];
        while (binaryStream.read(buffer) > 0) {
            arrayOutputStream.write(buffer);
        }
    } catch (SQLException sqlException) {
        sqlException.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return arrayOutputStream.toByteArray();
}
 
Example 5
Project: asura   File: MSSQLDelegate.java   View Source Code Vote up 7 votes
/**
 * <p>
 * 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 {
    InputStream binaryInput = rs.getBinaryStream(colName);

    if(binaryInput == null || binaryInput.available() == 0) {
        return null;
    }

    Object obj = null;

    ObjectInputStream in = new ObjectInputStream(binaryInput);
    try {
        obj = in.readObject();
    } finally {
        in.close();
    }

    return obj;
}
 
Example 6
Project: fresco_floodlight   File: JavaDBStorageEngine.java   View Source Code Vote up 6 votes
private static List<Versioned<byte[]>> getVersionedList(ResultSet rs) 
            throws SQLException, JsonParseException, 
                JsonMappingException, IOException {
    InputStream is = rs.getBinaryStream("datavalue");
    return mapper.readValue(is,
                            new TypeReference<List<VCVersioned<byte[]>>>() {});
}
 
Example 7
Project: urule   File: DbPersistenceManager.java   View Source Code Vote up 6 votes
/**
 * Reads and parses a bundle from the BLOB in the given column of the
 * current row of the given result set. This is a helper method to
 * circumvent issues JCR-1039 and JCR-1474.
 *
 * @param id bundle identifier
 * @param rs result set
 * @param column BLOB column
 * @return parsed bundle
 * @throws SQLException if the bundle can not be read or parsed
 */
private NodePropBundle readBundle(NodeId id, ResultSet rs, int column)
        throws SQLException {
    try {
        InputStream in;
        if (rs.getMetaData().getColumnType(column) == Types.BLOB) {
            in = rs.getBlob(column).getBinaryStream();
        } else {
            in = rs.getBinaryStream(column);
        }
        try {
            return binding.readBundle(in, id);
        } finally {
            in.close();
        }
    } catch (IOException e) {
        SQLException exception =
            new SQLException("Failed to parse bundle " + id);
        exception.initCause(e);
        throw exception;
    }
}
 
Example 8
Project: calcite-avatica   File: AvaticaResultSetConversionsTest.java   View Source Code Vote up 6 votes
public void testGetBinaryStream(ResultSet resultSet) throws SQLException {
  try {
    resultSet.getBinaryStream(ordinal);
    fail("Was expecting to throw SQLDataException");
  } catch (Exception e) {
    assertThat(e, isA((Class) SQLDataException.class)); // success
  }
}
 
Example 9
Project: lams   File: DefaultLobHandler.java   View Source Code Vote up 6 votes
@Override
public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException {
	logger.debug("Returning BLOB as binary stream");
	if (this.wrapAsLob) {
		Blob blob = rs.getBlob(columnIndex);
		return blob.getBinaryStream();
	}
	else {
		return rs.getBinaryStream(columnIndex);
	}
}
 
Example 10
Project: lams   File: MSSQLDelegate.java   View Source Code Vote up 6 votes
/**
 * <p>
 * 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
 */
@Override           
protected Object getObjectFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    InputStream binaryInput = rs.getBinaryStream(colName);

    if(binaryInput == null || binaryInput.available() == 0) {
        return null;
    }

    Object obj = null;

    ObjectInputStream in = new ObjectInputStream(binaryInput);
    try {
        obj = in.readObject();
    } finally {
        in.close();
    }

    return obj;
}
 
Example 11
Project: lams   File: MSSQLDelegate.java   View Source Code Vote up 6 votes
@Override           
protected Object getJobDataFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    if (canUseProperties()) {
        InputStream binaryInput = rs.getBinaryStream(colName);
        return binaryInput;
    }
    return getObjectFromBlob(rs, colName);
}
 
Example 12
Project: lams   File: SybaseDelegate.java   View Source Code Vote up 6 votes
@Override           
protected Object getJobDataFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    if (canUseProperties()) {
        InputStream binaryInput = rs.getBinaryStream(colName);
        return binaryInput;
    }
    return getObjectFromBlob(rs, colName);
}
 
Example 13
Project: lams   File: HSQLDBDelegate.java   View Source Code Vote up 6 votes
@Override           
protected Object getJobDataFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    if (canUseProperties()) {
        InputStream binaryInput = rs.getBinaryStream(colName);
        return binaryInput;
    }
    return getObjectFromBlob(rs, colName);
}
 
Example 14
Project: lams   File: OracleDelegate.java   View Source Code Vote up 6 votes
@Override
protected Object getJobDataFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    
    if (canUseProperties()) {
        InputStream binaryInput = rs.getBinaryStream(colName);
        return binaryInput;
    }

    return getObjectFromBlob(rs, colName);
}
 
Example 15
Project: lams   File: AbstractBynaryType.java   View Source Code Vote up 6 votes
public Object get(ResultSet rs, String name) throws HibernateException, SQLException {

		if ( Environment.useStreamsForBinary() ) {

			InputStream inputStream = rs.getBinaryStream(name);

			if (inputStream==null) return toExternalFormat( null ); // is this really necessary?

			ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048);
			byte[] buffer = new byte[2048];

			try {
				while (true) {
					int amountRead = inputStream.read(buffer);
					if (amountRead == -1) {
						break;
					}
					outputStream.write(buffer, 0, amountRead);
				}

				inputStream.close();
				outputStream.close();
			}
			catch (IOException ioe) {
				throw new HibernateException( "IOException occurred reading a binary value", ioe );
			}

			return toExternalFormat( outputStream.toByteArray() );

		}
		else {
			return toExternalFormat( rs.getBytes(name) );
		}
	}
 
Example 16
Project: asura   File: MSSQLDelegate.java   View Source Code Vote up 6 votes
protected Object getJobDetailFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    if (canUseProperties()) {
        InputStream binaryInput = rs.getBinaryStream(colName);
        return binaryInput;
    }
    return getObjectFromBlob(rs, colName);
}
 
Example 17
Project: iTAP-controller   File: JavaDBStorageEngine.java   View Source Code Vote up 6 votes
private static List<Versioned<byte[]>> getVersionedList(ResultSet rs) 
            throws SQLException, JsonParseException, 
                JsonMappingException, IOException {
    InputStream is = rs.getBinaryStream("datavalue");
    return mapper.readValue(is,
                            new TypeReference<List<VCVersioned<byte[]>>>() {});
}
 
Example 18
Project: asura   File: HSQLDBDelegate.java   View Source Code Vote up 6 votes
protected Object getJobDetailFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    if (canUseProperties()) {
        InputStream binaryInput = rs.getBinaryStream(colName);
        return binaryInput;
    }
    return getObjectFromBlob(rs, colName);
}
 
Example 19
Project: ChronoBike   File: ColValueBinaryStream.java   View Source Code Vote up 5 votes
public void doFillWithResurltSetCol(ResultSet resultSet, int nCol)
	throws SQLException
{
	m_is = resultSet.getBinaryStream(nCol);
}
 
Example 20
Project: oscm   File: MigrateTriggers.java   View Source Code Vote up 4 votes
/**
 * Retrieves the object from the serialized format.
 * 
 * @param <T>
 *            The object type.
 * @param is
 *            The result set, containing the serialized format of the
 *            object.
 * @param expectedClass
 *            The expected class of the object.
 * @return The object.
 */
<T> T getObjectFromXML(ResultSet resultSet, Class<T> expectedClass)
        throws SQLException {
    InputStream is = null;
    try {
        is = resultSet.getBinaryStream("value");
        XMLDecoder decoder = newXmlDecoder(is);
        return expectedClass.cast(decoder.readObject());
    } finally {
        closeStream(is);
    }
}