本文整理匯總了Java中java.sql.ResultSet.getBlob方法的典型用法代碼示例。如果您正苦於以下問題:Java ResultSet.getBlob方法的具體用法?Java ResultSet.getBlob怎麽用?Java ResultSet.getBlob使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.sql.ResultSet
的用法示例。
在下文中一共展示了ResultSet.getBlob方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getExecLog
import java.sql.ResultSet; //導入方法依賴的package包/類
public String getExecLog(long execId, String jobName)
throws SQLException, IOException {
System.out.println("start");
String cmd = "select log from execution_logs where exec_id = " + execId +
" and name = '" + jobName + "'and attempt = 0 order by start_byte;";
System.out.println(cmd);
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery(cmd);
StringBuilder sb = new StringBuilder();
while (rs.next()) {
Blob logBlob = rs.getBlob("log");
GZIPInputStream gzip = new GZIPInputStream(logBlob.getBinaryStream());
sb.append(IOUtils.toString(gzip, "UTF-8"));
}
statement.close();
System.out.println("stop");
return sb.toString();
}
示例2: getObjectFromBlob
import java.sql.ResultSet; //導入方法依賴的package包/類
/**
* <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 {
Object obj = null;
Blob blobLocator = rs.getBlob(colName);
if (blobLocator != null && blobLocator.length() != 0) {
InputStream binaryInput = blobLocator.getBinaryStream();
if (null != binaryInput) {
if (binaryInput instanceof ByteArrayInputStream
&& ((ByteArrayInputStream) binaryInput).available() == 0 ) {
//do nothing
} else {
ObjectInputStream in = new ObjectInputStream(binaryInput);
try {
obj = in.readObject();
} finally {
in.close();
}
}
}
}
return obj;
}
示例3: getJobDataFromBlob
import java.sql.ResultSet; //導入方法依賴的package包/類
@Override
protected Object getJobDataFromBlob(ResultSet rs, String colName)
throws ClassNotFoundException, IOException, SQLException {
if (canUseProperties()) {
Blob blobLocator = rs.getBlob(colName);
InputStream binaryInput = null;
try {
if (null != blobLocator && blobLocator.length() > 0) {
binaryInput = blobLocator.getBinaryStream();
}
} catch (Exception ignore) {
}
return binaryInput;
}
return getObjectFromBlob(rs, colName);
}
示例4: getBlobAsBytes
import java.sql.ResultSet; //導入方法依賴的package包/類
@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;
}
示例5: getObjectFromBlob
import java.sql.ResultSet; //導入方法依賴的package包/類
/**
* <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 {
Object obj = null;
Blob blobLocator = rs.getBlob(colName);
InputStream binaryInput = null;
try {
if (null != blobLocator && blobLocator.length() > 0) {
binaryInput = blobLocator.getBinaryStream();
}
} catch (Exception ignore) {
}
if (null != binaryInput) {
ObjectInputStream in = new ObjectInputStream(binaryInput);
try {
obj = in.readObject();
} finally {
in.close();
}
}
return obj;
}
示例6: getBigData
import java.sql.ResultSet; //導入方法依賴的package包/類
/**
* 用於查詢記錄中大數據類型值,若有多條記錄符合要求則返回第一條記錄的大數據
*
* @param sql 查詢SQL語句,查詢字段的類型必須為Blob類型
* @param arg 傳入的占位符的參數
* @return 返回查詢的大數據,封裝在Map中,若沒有符合條件的記錄則返回空Map
*/
public static Map<String, byte[]> getBigData(String sql, Object... arg) {
Map<String, byte[]> bigDataMap = new HashMap<String, byte[]>();
Connection connection = JDBCUtils.getConnection();
PreparedStatement ps = null;
ResultSet result = null;
// 填充占位符
try {
ps = connection.prepareStatement(sql);
for (int i = 0; i < arg.length; i++) {
ps.setObject(i + 1, arg[i]);
}
// 執行SQL語句
result = ps.executeQuery();
// 獲取字段名
List<String> columnList = DBUtils.getColumnLabels(result);
// 遍曆結果集
while (result.next()) {
// 遍曆字段名獲取相應大數據值
for (String column : columnList) {
Blob data = result.getBlob(column);
byte[] datas = data.getBytes(1, (int) data.length());
bigDataMap.put(column, datas);
}
break;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
JDBCUtils.release(result, ps, connection);
}
return bigDataMap;
}
示例7: getBlobAsBinaryStream
import java.sql.ResultSet; //導入方法依賴的package包/類
@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;
}
示例8: getNullableResult
import java.sql.ResultSet; //導入方法依賴的package包/類
@Override
public byte[] getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
Blob blob = rs.getBlob(columnIndex);
byte[] returnValue = null;
if (null != blob) {
returnValue = blob.getBytes(1, (int) blob.length());
}
return returnValue;
}
示例9: getBlobAsBinaryStream
import java.sql.ResultSet; //導入方法依賴的package包/類
@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);
}
}
示例10: getObjectFromBlob
import java.sql.ResultSet; //導入方法依賴的package包/類
/**
* {@inheritDoc}
* <p>
* Caché requires {@code java.sql.Blob} instances to be explicitly freed.
*/
@Override
protected Object getObjectFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException {
Blob blob = rs.getBlob(colName);
if (blob == null) {
return null;
} else {
try {
if (blob.length() == 0) {
return null;
} else {
InputStream binaryInput = blob.getBinaryStream();
if (binaryInput == null) {
return null;
} else if (binaryInput instanceof ByteArrayInputStream && ((ByteArrayInputStream) binaryInput).available() == 0 ) {
return null;
} else {
ObjectInputStream in = new ObjectInputStream(binaryInput);
try {
return in.readObject();
} finally {
in.close();
}
}
}
} finally {
blob.free();
}
}
}
示例11: writeDataToBlob
import java.sql.ResultSet; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
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!");
}
if (blob instanceof oracle.sql.BLOB) { // is it an oracle blob?
((oracle.sql.BLOB) blob).putBytes(1, data);
((oracle.sql.BLOB) blob).trim(data.length);
return blob;
} else {
throw new SQLException(
"Driver's Blob representation is of an unsupported type: "
+ blob.getClass().getName());
}
}
示例12: get
import java.sql.ResultSet; //導入方法依賴的package包/類
protected Object get(ResultSet rs, String name) throws SQLException {
Blob blob = rs.getBlob( name );
if ( rs.wasNull() ) return null;
int length = (int) blob.length();
byte[] primaryResult = blob.getBytes( 1, length );
return wrap( primaryResult );
}
示例13: readBlobRef
import java.sql.ResultSet; //導入方法依賴的package包/類
/**
* Actually read a BlobRef instance from the ResultSet and materialize
* the data either inline or to a file.
*
* @param colNum the column of the ResultSet's current row to read.
* @param r the ResultSet to read from.
* @return a BlobRef encapsulating the data in this field.
* @throws IOException if an error occurs writing to the FileSystem.
* @throws SQLException if an error occurs reading from the database.
*/
public com.cloudera.sqoop.lib.BlobRef readBlobRef(int colNum, ResultSet r)
throws IOException, InterruptedException, SQLException {
long maxInlineLobLen = conf.getLong(
MAX_INLINE_LOB_LEN_KEY,
DEFAULT_MAX_LOB_LENGTH);
Blob b = r.getBlob(colNum);
if (null == b) {
return null;
} else if (b.length() > maxInlineLobLen) {
// Deserialize very large BLOBs into separate files.
long len = b.length();
LobFile.Writer lobWriter = getBlobWriter();
long recordOffset = lobWriter.tell();
InputStream is = null;
OutputStream os = lobWriter.writeBlobRecord(len);
try {
is = b.getBinaryStream();
copyAll(is, os);
} finally {
if (null != os) {
os.close();
}
if (null != is) {
is.close();
}
// Mark the record as finished.
lobWriter.finishRecord();
}
return new com.cloudera.sqoop.lib.BlobRef(
getRelativePath(curBlobWriter), recordOffset, len);
} else {
// This is a 1-based array.
return new com.cloudera.sqoop.lib.BlobRef(
b.getBytes(1, (int) b.length()));
}
}
示例14: get
import java.sql.ResultSet; //導入方法依賴的package包/類
@Override
public Object get(ResultSet resultSet, int index) throws SQLException {
Blob blob = resultSet.getBlob(index);
if (blob != null) {
ByteBuffer wrap = ByteBuffer.wrap(blob.getBytes(0, (int) blob.length()));
return serializer.deserialize(wrap);
}
return null;
}
示例15: testGetClob
import java.sql.ResultSet; //導入方法依賴的package包/類
public void testGetClob(ResultSet resultSet) throws SQLException {
try {
resultSet.getBlob(ordinal);
fail("Was expecting to throw SQLDataException");
} catch (Exception e) {
assertThat(e, isA((Class) SQLDataException.class)); // success
}
}