当前位置: 首页>>代码示例>>Java>>正文


Java ResultSet.getBlob方法代码示例

本文整理汇总了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();
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:19,代码来源:AzDbCommunicator.java

示例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;
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:43,代码来源:StdJDBCDelegate.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:WebLogicDelegate.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:OracleLobHandler.java

示例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;
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:43,代码来源:WebLogicDelegate.java

示例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;
}
 
开发者ID:FlyingHe,项目名称:UtilsMaven,代码行数:44,代码来源:DBUtils.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:OracleLobHandler.java

示例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;
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:10,代码来源:BlobTypeHandler.java

示例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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:DefaultLobHandler.java

示例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();
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:CacheDelegate.java

示例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());
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:OracleDelegate.java

示例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 );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:ByteArrayBlobType.java

示例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()));
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:53,代码来源:LargeObjectLoader.java

示例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;
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:10,代码来源:BlobValueTransformer.java

示例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
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:9,代码来源:AvaticaResultSetConversionsTest.java


注:本文中的java.sql.ResultSet.getBlob方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。