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


Java PreparedStatement.setBlob方法代码示例

本文整理汇总了Java中java.sql.PreparedStatement.setBlob方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatement.setBlob方法的具体用法?Java PreparedStatement.setBlob怎么用?Java PreparedStatement.setBlob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.PreparedStatement的用法示例。


在下文中一共展示了PreparedStatement.setBlob方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setNonNullParameter

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Map parameter, JdbcType jdbcType) throws SQLException {
    if (parameter != null && parameter.size() > 0) {
        LOGGER.debug("Input-Map before serializing: ", parameter);
        // Convert Map to byte array
        try (ByteArrayOutputStream byteOut = new ByteArrayOutputStream()) {
            ObjectOutputStream out = new ObjectOutputStream(byteOut);
            out.writeObject(parameter);
            ps.setBlob(i, new ByteArrayInputStream(byteOut.toByteArray()));
            out.close();
        } catch (IOException e) {
            LOGGER.error("During serialization of 'customAttributes' an error occured: ", e);
        }
    } else {
        ps.setNull(i, Types.BLOB);
    }
}
 
开发者ID:Taskana,项目名称:taskana,代码行数:18,代码来源:MapTypeHandler.java

示例2: setReplicationDataBlob

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private static void setReplicationDataBlob ( final PreparedStatement stmt, final Event event ) throws SQLException, IOException
{
    final Blob blob = stmt.getConnection ().createBlob ();

    final ObjectOutputStream oos = new ObjectOutputStream ( blob.setBinaryStream ( 1 ) );
    oos.writeObject ( event );
    oos.close ();

    stmt.setBlob ( 4, blob );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:11,代码来源:AbstractJdbcStorageDao.java

示例3: setBlobAsBinaryStream

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setBlobAsBinaryStream(
		PreparedStatement ps, int paramIndex, InputStream binaryStream, int contentLength)
		throws SQLException {

	Blob blob = ps.getConnection().createBlob();
	try {
		FileCopyUtils.copy(binaryStream, blob.setBinaryStream(1));
	}
	catch (IOException ex) {
		throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex);
	}

	this.temporaryBlobs.add(blob);
	ps.setBlob(paramIndex, blob);

	if (logger.isDebugEnabled()) {
		logger.debug(binaryStream != null ?
				"Copied binary stream into temporary BLOB with length " + contentLength :
				"Set BLOB to null");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:TemporaryLobCreator.java

示例4: setBlobAsBytes

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setBlobAsBytes(PreparedStatement ps, int paramIndex, final byte[] content)
		throws SQLException {

	if (content != null) {
		Blob blob = (Blob) createLob(ps, false, new LobCallback() {
			@Override
			public void populateLob(Object lob) throws Exception {
				Method methodToInvoke = lob.getClass().getMethod("getBinaryOutputStream");
				OutputStream out = (OutputStream) methodToInvoke.invoke(lob);
				FileCopyUtils.copy(content, out);
			}
		});
		ps.setBlob(paramIndex, blob);
		if (logger.isDebugEnabled()) {
			logger.debug("Set bytes for Oracle BLOB with length " + blob.length());
		}
	}
	else {
		ps.setBlob(paramIndex, (Blob) null);
		logger.debug("Set Oracle BLOB to null");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:OracleLobHandler.java

示例5: setBlobAsBinaryStream

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setBlobAsBinaryStream(
		PreparedStatement ps, int paramIndex, final InputStream binaryStream, int contentLength)
		throws SQLException {

	if (binaryStream != null) {
		Blob blob = (Blob) createLob(ps, false, new LobCallback() {
			@Override
			public void populateLob(Object lob) throws Exception {
				Method methodToInvoke = lob.getClass().getMethod("getBinaryOutputStream", (Class[]) null);
				OutputStream out = (OutputStream) methodToInvoke.invoke(lob, (Object[]) null);
				FileCopyUtils.copy(binaryStream, out);
			}
		});
		ps.setBlob(paramIndex, blob);
		if (logger.isDebugEnabled()) {
			logger.debug("Set binary stream for Oracle BLOB with length " + blob.length());
		}
	}
	else {
		ps.setBlob(paramIndex, (Blob) null);
		logger.debug("Set Oracle BLOB to null");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:OracleLobHandler.java

示例6: set

import java.sql.PreparedStatement; //导入方法依赖的package包/类
protected void set(PreparedStatement st, Object value, int index, SessionImplementor session) throws SQLException {
	if ( value == null ) {
		st.setNull( index, sqlTypes( null )[0] );
	}
	else {
		byte[] toSet = unWrap( value );
		final boolean useInputStream = session.getFactory().getDialect().useInputStreamToInsertBlob();

		if ( useInputStream ) {
			st.setBinaryStream( index, new ByteArrayInputStream( toSet ), toSet.length );
		}
		else {
			st.setBlob( index, Hibernate.getLobCreator( session ).createBlob( toSet ) );
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:ByteArrayBlobType.java

示例7: setAppObject

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/** Sets a parameter in the PreparedStatement.
 * @param engineType The engine type as defined in init.xml
 * @param pstmt The PreparedStatement.
 * @param parameterIndex The index of the parameter that is to be set.
 * @param value The object to be assigned to the parameter.
 * @throws SQLException if a database access error occurs.
 */
public void setAppObject(PreparedStatement pstmt, int parameterIndex, Object value, String engineType)
throws SQLException {
    if (value != null) {
        if (!(value instanceof byte[]))
            value = DataTypeMapper.instance().map(value, byte[].class);
        if ("oracle".equalsIgnoreCase(engineType) && !supportsStdLob(pstmt)) {
            Blob blob = createBlob(pstmt.getConnection(), (byte[]) value);
            pstmt.setBlob(parameterIndex, blob);
        } else {
            byte[] bytes = (byte[]) value;
            InputStream stream = new BufferedInputStream(new ByteArrayInputStream(bytes));
            pstmt.setBinaryStream(parameterIndex, stream, bytes.length);
        }
    } else
        pstmt.setNull(parameterIndex, getSqlType(Defaults.BLOB, engineType));
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:24,代码来源:TypeDefs.java

示例8: setBlobAsBytes

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setBlobAsBytes(PreparedStatement ps, int paramIndex, byte[] content)
		throws SQLException {

	Blob blob = ps.getConnection().createBlob();
	blob.setBytes(1, content);

	this.temporaryBlobs.add(blob);
	ps.setBlob(paramIndex, blob);

	if (logger.isDebugEnabled()) {
		logger.debug(content != null ? "Copied bytes into temporary BLOB with length " + content.length :
				"Set BLOB to null");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:TemporaryLobCreator.java

示例9: setBlobAsBytes

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setBlobAsBytes(PreparedStatement ps, int paramIndex, byte[] content)
		throws SQLException {

	if (streamAsLob) {
		if (content != null) {
			ps.setBlob(paramIndex, new ByteArrayInputStream(content), content.length);
		}
		else {
			ps.setBlob(paramIndex, (Blob) null);
		}
	}
	else if (wrapAsLob) {
		if (content != null) {
			ps.setBlob(paramIndex, new PassThroughBlob(content));
		}
		else {
			ps.setBlob(paramIndex, (Blob) null);
		}
	}
	else {
		ps.setBytes(paramIndex, content);
	}
	if (logger.isDebugEnabled()) {
		logger.debug(content != null ? "Set bytes for BLOB with length " + content.length :
				"Set BLOB to null");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:DefaultLobHandler.java

示例10: setBlobAsBinaryStream

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setBlobAsBinaryStream(
		PreparedStatement ps, int paramIndex, InputStream binaryStream, int contentLength)
		throws SQLException {

	if (streamAsLob) {
		if (binaryStream != null) {
			ps.setBlob(paramIndex, binaryStream, contentLength);
		}
		else {
			ps.setBlob(paramIndex, (Blob) null);
		}
	}
	else if (wrapAsLob) {
		if (binaryStream != null) {
			ps.setBlob(paramIndex, new PassThroughBlob(binaryStream, contentLength));
		}
		else {
			ps.setBlob(paramIndex, (Blob) null);
		}
	}
	else {
		ps.setBinaryStream(paramIndex, binaryStream, contentLength);
	}
	if (logger.isDebugEnabled()) {
		logger.debug(binaryStream != null ? "Set binary stream for BLOB with length " + contentLength :
				"Set BLOB to null");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:DefaultLobHandler.java

示例11: insertCalendar

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public int insertCalendar(Connection conn, String calendarName,
        Calendar calendar) throws IOException, SQLException {
    ByteArrayOutputStream baos = serializeObject(calendar);

    PreparedStatement ps = null;
    PreparedStatement ps2 = null;
    ResultSet rs = null;

    try {
        ps = conn.prepareStatement(rtp(INSERT_ORACLE_CALENDAR));
        ps.setString(1, calendarName);

        ps.executeUpdate();
        ps.close();

        ps = conn.prepareStatement(rtp(SELECT_ORACLE_CALENDAR_BLOB));
        ps.setString(1, calendarName);

        rs = ps.executeQuery();

        if (rs.next()) {
            Blob dbBlob = writeDataToBlob(rs, 1, baos.toByteArray());
            ps2 = conn.prepareStatement(rtp(UPDATE_ORACLE_CALENDAR_BLOB));

            ps2.setBlob(1, dbBlob);
            ps2.setString(2, calendarName);

            return ps2.executeUpdate();
        }

        return 0;

    } finally {
        closeResultSet(rs);
        closeStatement(ps);
        closeStatement(ps2);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:OracleDelegate.java

示例12: updateCalendar

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public int updateCalendar(Connection conn, String calendarName,
        Calendar calendar) throws IOException, SQLException {
    ByteArrayOutputStream baos = serializeObject(calendar);

    PreparedStatement ps = null;
    PreparedStatement ps2 = null;
    ResultSet rs = null;

    try {
        ps = conn.prepareStatement(rtp(SELECT_ORACLE_CALENDAR_BLOB));
        ps.setString(1, calendarName);

        rs = ps.executeQuery();

        if (rs.next()) {
            Blob dbBlob = writeDataToBlob(rs, 1, baos.toByteArray());
            ps2 = conn.prepareStatement(rtp(UPDATE_ORACLE_CALENDAR_BLOB));

            ps2.setBlob(1, dbBlob);
            ps2.setString(2, calendarName);

            return ps2.executeUpdate();
        }

        return 0;

    } finally {
        closeResultSet(rs);
        closeStatement(ps);
        closeStatement(ps2);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:OracleDelegate.java

示例13: updateJobData

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public int updateJobData(Connection conn, JobDetail job)
    throws IOException, SQLException {
    
    ByteArrayOutputStream baos = serializeJobData(job.getJobDataMap());
    byte[] data = baos.toByteArray();

    PreparedStatement ps = null;
    PreparedStatement ps2 = null;
    ResultSet rs = null;

    try {
        ps = conn.prepareStatement(rtp(SELECT_ORACLE_JOB_DETAIL_BLOB));
        ps.setString(1, job.getKey().getName());
        ps.setString(2, job.getKey().getGroup());

        rs = ps.executeQuery();

        int res = 0;

        if (rs.next()) {
            Blob dbBlob = writeDataToBlob(rs, 1, data);
            ps2 = conn.prepareStatement(rtp(UPDATE_ORACLE_JOB_DETAIL_BLOB));

            ps2.setBlob(1, dbBlob);
            ps2.setString(2, job.getKey().getName());
            ps2.setString(3, job.getKey().getGroup());

            res = ps2.executeUpdate();
        }

        return res;
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
        closeStatement(ps2);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:OracleDelegate.java

示例14: getBlobBinder

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public <X> BasicBinder<X> getBlobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
	return new BasicBinder<X>( javaTypeDescriptor, this ) {
		@Override
		protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
				throws SQLException {
			st.setBlob( index, javaTypeDescriptor.unwrap( value, Blob.class, options ) );
		}
	};
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:BlobTypeDescriptor.java

示例15: insertJobDetail

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public int insertJobDetail(Connection conn, JobDetail job)
    throws IOException, SQLException {

    ByteArrayOutputStream baos = serializeJobData(job.getJobDataMap());
    byte[] data = baos.toByteArray();
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        ps = conn.prepareStatement(rtp(INSERT_ORACLE_JOB_DETAIL));
        ps.setString(1, job.getKey().getName());
        ps.setString(2, job.getKey().getGroup());
        ps.setString(3, job.getDescription());
        ps.setString(4, job.getJobClass().getName());
        setBoolean(ps, 5, job.isDurable());
        setBoolean(ps, 6, job.isConcurrentExectionDisallowed());
        setBoolean(ps, 7, job.isPersistJobDataAfterExecution());
        setBoolean(ps, 8, job.requestsRecovery());

        ps.executeUpdate();
        ps.close();

        ps = conn.prepareStatement(rtp(SELECT_ORACLE_JOB_DETAIL_BLOB));
        ps.setString(1, job.getKey().getName());
        ps.setString(2, job.getKey().getGroup());

        rs = ps.executeQuery();

        int res = 0;

        Blob dbBlob = null;
        if (rs.next()) {
            dbBlob = writeDataToBlob(rs, 1, data);
        } else {
            return res;
        }

        rs.close();
        ps.close();

        ps = conn.prepareStatement(rtp(UPDATE_ORACLE_JOB_DETAIL_BLOB));
        ps.setBlob(1, dbBlob);
        ps.setString(2, job.getKey().getName());
        ps.setString(3, job.getKey().getGroup());

        res = ps.executeUpdate();

        return res;
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:56,代码来源:OracleDelegate.java


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