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:org.wso2.carbon.apimgt.hybrid.gateway.usage.publisher.dao.UploadedUsageFileInfoDAO.java
/** * Get the content of the file based on the file information * * @param dto Processed file represented by {@link UploadedFileInfoDTO} * @return InputStream with the content of the file of null if there is no content * @throws UsagePublisherException/* w ww . j a v a 2 s . c om*/ */ public static InputStream getFileContent(UploadedFileInfoDTO dto) throws UsagePublisherException { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; InputStream fileContentInputStream = null; try { connection = APIMgtDBUtil.getConnection(); statement = connection.prepareStatement(MicroGatewayAPIUsageConstants.GET_UPLOADED_FILE_CONTENT_QUERY); statement.setString(1, dto.getTenantDomain()); statement.setString(2, dto.getFileName()); resultSet = statement.executeQuery(); while (resultSet.next()) { //Postgres bytea data doesn't support getBlob operation if (connection.getMetaData().getDriverName().contains("PostgreSQL")) { fileContentInputStream = resultSet .getBinaryStream(MicroGatewayAPIUsageConstants.API_USAGE_FILE_CONTENT); } else { Blob content = resultSet.getBlob(MicroGatewayAPIUsageConstants.API_USAGE_FILE_CONTENT); fileContentInputStream = content.getBinaryStream(); } if (log.isDebugEnabled()) { log.debug("Added File to list : " + dto.toString()); } } if (log.isDebugEnabled()) { log.debug("Retrieved content of file : " + dto.toString()); } } catch (SQLException e) { throw new UsagePublisherException( "Error occurred while retrieving the content of the file: " + dto.toString(), e); } finally { APIMgtDBUtil.closeAllConnections(statement, connection, resultSet); } return fileContentInputStream; }
From source file:com.siemens.scr.avt.ad.hibernate.BinaryBlobType.java
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { Blob blob = rs.getBlob(names[0]); return blob.getBytes(1, (int) blob.length()); }
From source file:org.georepublic.db.utils.ResultSetConverter.java
public static JSONArray convert(ResultSet rs) throws SQLException, JSONException { JSONArray json = new JSONArray(); ResultSetMetaData rsmd = rs.getMetaData(); while (rs.next()) { int numColumns = rsmd.getColumnCount(); JSONObject obj = new JSONObject(); for (int i = 1; i < numColumns + 1; i++) { String column_name = rsmd.getColumnName(i); if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) { obj.put(column_name, rs.getArray(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) { obj.put(column_name, rs.getBoolean(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BLOB) { obj.put(column_name, rs.getBlob(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) { obj.put(column_name, rs.getDouble(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) { obj.put(column_name, rs.getFloat(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) { obj.put(column_name, rs.getNString(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.VARCHAR) { obj.put(column_name, rs.getString(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) { obj.put(column_name, rs.getDate(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) { obj.put(column_name, rs.getTimestamp(column_name)); } else { obj.put(column_name, rs.getObject(column_name)); }/* w w w . j a va2 s . com*/ } json.put(obj); } return json; }
From source file:org.quartz.impl.jdbcjobstore.oracle.weblogic.WebLogicOracleDelegate.java
/** * Check for the Weblogic Blob wrapper, and handle accordingly... *//*from w w w .ja v a 2 s . co m*/ protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data) throws SQLException { Blob blob = rs.getBlob(column); if (blob == null) { throw new SQLException("Driver's Blob representation is null!"); } // handle thin driver's blob if (blob instanceof weblogic.jdbc.vendor.oracle.OracleThinBlob) { ((weblogic.jdbc.vendor.oracle.OracleThinBlob) blob).putBytes(1, data); return blob; } else if (blob.getClass().getPackage().getName().startsWith("weblogic.")) { // (more slowly) handle blob for wrappers of other variations of drivers... try { // try to find putBytes method... Method m = blob.getClass().getMethod("putBytes", new Class[] { long.class, byte[].class }); m.invoke(blob, new Object[] { new Long(1), data }); } catch (Exception e) { try { // Added this logic to the original code from OpenSymphony // putBytes method does not exist. Try setBytes Method m = blob.getClass().getMethod("setBytes", new Class[] { long.class, byte[].class }); m.invoke(blob, new Object[] { new Long(1), data }); } catch (Exception e2) { throw new SQLException( "Unable to find putBytes(long,byte[]) or setBytes(long,byte[]) methods on blob: " + e2); } } return blob; } else { return super.writeDataToBlob(rs, column, data); } }
From source file:com.butler.service.ProductDao.java
public InputStream getImage(String product) { String sql = "select pic from product where name='" + product + "'"; return (InputStream) this.getJdbcTemplate().query(sql, new ResultSetExtractor() { public Object extractData(ResultSet rs) throws SQLException, DataAccessException { rs.next();// w w w . ja v a2s. co m Blob imageBlob = rs.getBlob("pic"); InputStream binaryStream = imageBlob.getBinaryStream(1, imageBlob.length()); return binaryStream; } }); }
From source file:metadata.etl.lineage.AzDbCommunicator.java
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);// w ww . java2s . c o m 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(); }
From source file:org.opencms.db.oracle.CmsSqlManager.java
/** * @see org.opencms.db.generic.CmsSqlManager#getBytes(java.sql.ResultSet, java.lang.String) *///w w w . j a v a2s . c om @Override public byte[] getBytes(ResultSet res, String attributeName) throws SQLException { Blob blob = res.getBlob(attributeName); return blob.getBytes(1, (int) blob.length()); }
From source file:nl.nn.adapterframework.util.JdbcUtil.java
public static InputStream getBlobInputStream(ResultSet rs, int columnIndex) throws SQLException, JdbcException { return getBlobInputStream(rs.getBlob(columnIndex), columnIndex + ""); }
From source file:org.quartz.impl.jdbcjobstore.WebLogicDelegate.java
/** * <p>/*from w ww. ja v a2 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 { 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; }
From source file:org.quartz.impl.jdbcjobstore.WebLogicDelegate.java
protected Object getJobDetailFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { if (canUseProperties()) { Blob blobLocator = rs.getBlob(colName); InputStream binaryInput = null; try {//from w w w. ja v a2 s. com if (null != blobLocator && blobLocator.length() > 0) { binaryInput = blobLocator.getBinaryStream(); } } catch (Exception ignore) { } return binaryInput; } return getObjectFromBlob(rs, colName); }