本文整理汇总了Java中java.sql.PreparedStatement.setBinaryStream方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatement.setBinaryStream方法的具体用法?Java PreparedStatement.setBinaryStream怎么用?Java PreparedStatement.setBinaryStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.PreparedStatement
的用法示例。
在下文中一共展示了PreparedStatement.setBinaryStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateCalendar
import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
* <p>
* Update a calendar.
* </p>
*
* @param conn
* the DB Connection
* @param calendarName
* the name for the new calendar
* @param calendar
* the calendar
* @return the number of rows updated
* @throws IOException
* if there were problems serializing the calendar
*/
public int updateCalendar(Connection conn, String calendarName,
Calendar calendar) throws IOException, SQLException {
//log.debug( "Updating calendar " + calendarName + " : " + calendar );
ByteArrayOutputStream baos = serializeObject(calendar);
byte buf[] = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(UPDATE_CALENDAR));
ps.setBinaryStream(1, bais, buf.length);
ps.setString(2, calendarName);
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
示例2: setParameter
import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException
{
if (parameter == null)
{
ps.setNull(i, SerializableTypeHandler.serializableType);
}
else
{
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(parameter);
byte[] bytes = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ps.setBinaryStream(i, bais, bytes.length);
}
catch (Throwable e)
{
throw new SerializationException(e);
}
}
}
示例3: 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));
}
示例4: updateJobData
import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
* <p>
* Update the job data map for the given job.
* </p>
*
* @param conn
* the DB Connection
* @param job
* the job to update
* @return the number of rows updated
*/
@Override
public int updateJobData(Connection conn, JobDetail job)
throws IOException, SQLException {
//log.debug( "Updating Job Data for Job " + job );
ByteArrayOutputStream baos = serializeJobData(job.getJobDataMap());
int len = baos.toByteArray().length;
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(UPDATE_JOB_DATA));
ps.setBinaryStream(1, bais, len);
ps.setString(2, job.getKey().getName());
ps.setString(3, job.getKey().getGroup());
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
示例5: insertCalendar
import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
* <p>
* Insert a new calendar.
* </p>
*
* @param conn
* the DB Connection
* @param calendarName
* the name for the new calendar
* @param calendar
* the calendar
* @return the number of rows inserted
* @throws IOException
* if there were problems serializing the calendar
*/
@Override
public int insertCalendar(Connection conn, String calendarName,
Calendar calendar) throws IOException, SQLException {
//log.debug( "Inserting Calendar " + calendarName + " : " + calendar
// );
ByteArrayOutputStream baos = serializeObject(calendar);
byte buf[] = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(INSERT_CALENDAR));
ps.setString(1, calendarName);
ps.setBinaryStream(2, bais, buf.length);
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
示例6: updateCalendar
import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
* <p>
* Update a calendar.
* </p>
*
* @param conn
* the DB Connection
* @param calendarName
* the name for the new calendar
* @param calendar
* the calendar
* @return the number of rows updated
* @throws IOException
* if there were problems serializing the calendar
*/
@Override
public int updateCalendar(Connection conn, String calendarName,
Calendar calendar) throws IOException, SQLException {
//log.debug( "Updating calendar " + calendarName + " : " + calendar );
ByteArrayOutputStream baos = serializeObject(calendar);
byte buf[] = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(UPDATE_CALENDAR));
ps.setBinaryStream(1, bais, buf.length);
ps.setString(2, calendarName);
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
示例7: 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 ) );
}
}
}
示例8: testPacketTooLargeException
import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
* Tests that PacketTooLargeException doesn't clober the connection.
*
* @throws Exception
* if the test fails.
*/
public void testPacketTooLargeException() throws Exception {
final ConnectionEventListener conListener = new ConnectionListener();
PooledConnection pc = null;
pc = this.cpds.getPooledConnection();
pc.addConnectionEventListener(conListener);
createTable("testPacketTooLarge", "(field1 LONGBLOB)");
Connection connFromPool = pc.getConnection();
PreparedStatement pstmtFromPool = ((ConnectionWrapper) connFromPool).clientPrepare("INSERT INTO testPacketTooLarge VALUES (?)");
this.rs = this.stmt.executeQuery("SHOW VARIABLES LIKE 'max_allowed_packet'");
this.rs.next();
int maxAllowedPacket = this.rs.getInt(2);
int numChars = (int) (maxAllowedPacket * 1.2);
pstmtFromPool.setBinaryStream(1, new BufferedInputStream(new FileInputStream(newTempBinaryFile("testPacketTooLargeException", numChars))), numChars);
try {
pstmtFromPool.executeUpdate();
fail("Expecting PacketTooLargeException");
} catch (PacketTooBigException ptbe) {
// We're expecting this one...
}
// This should still work okay, even though the last query on the same connection didn't...
this.rs = connFromPool.createStatement().executeQuery("SELECT 1");
assertTrue(this.connectionErrorEventCount == 0);
assertTrue(this.closeEventCount == 0);
}
示例9: addFormTemplates
import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void addFormTemplates(Connection connection)
throws Exception {
//1=FORM_ID, TEMPLATE_DATA, LAYOUT_DATA
String sql = "insert into J_FORM_TEMPLATES values (?,?,?)";
PreparedStatement pstmnt = connection.prepareStatement(sql);
// Create first record
pstmnt.setLong(1, 1000000);
URL u = URLHelper.newExtendedURL(PDF_TEMPLATE);
InputStream is = u.openStream();
pstmnt.setBinaryStream(2,is,is.available());
u = URLHelper.newExtendedURL(PDF_TEMPLATE+".csv");
is = u.openStream();
pstmnt.setBinaryStream(3,is,is.available());
pstmnt.execute();
pstmnt.clearParameters();
// Create second record
pstmnt.setLong(1, 1000001);
u = URLHelper.newExtendedURL(VELOCITY_TEMPLATE);
is = u.openStream();
pstmnt.setBinaryStream(2,is,is.available());
pstmnt.setObject(3,null);
pstmnt.execute();
pstmnt.clearParameters();
// Create third record
pstmnt.setLong(1, 1000002);
u = URLHelper.newExtendedURL(PDF_TEMPLATE3);
is = u.openStream();
pstmnt.setBinaryStream(2,is,is.available());
u = URLHelper.newExtendedURL(PDF_TEMPLATE3+".csv");
is = u.openStream();
pstmnt.setBinaryStream(3,is,is.available());
pstmnt.execute();
pstmnt.clearParameters();
pstmnt.close();
}
示例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");
}
}
示例11: 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 {
final BinaryStream binaryStream = javaTypeDescriptor.unwrap(
value,
BinaryStream.class,
options
);
st.setBinaryStream( index, binaryStream.getInputStream(), binaryStream.getLength() );
}
};
}
示例12: set
import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
byte[] internalValue = toInternalFormat( value );
if ( Environment.useStreamsForBinary() ) {
st.setBinaryStream( index, new ByteArrayInputStream( internalValue ), internalValue.length );
}
else {
st.setBytes( index, internalValue );
}
}
示例13: nullSafeSet
import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session) throws SQLException, HibernateException {
if (value == null) {
ps.setNull(index, sqlTypes()[0]);
} else {
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(new GZIPOutputStream(bytes),OutputFormat.createCompactFormat());
writer.write((Document)value);
writer.flush(); writer.close();
ps.setBinaryStream(index, new ByteArrayInputStream(bytes.toByteArray(),0,bytes.size()), bytes.size());
} catch (IOException e) {
throw new HibernateException(e.getMessage(),e);
}
}
}
示例14: insertJobDetail
import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
* <p>
* Insert the job detail record.
* </p>
*
* @param conn
* the DB Connection
* @param job
* the job to insert
* @return number of rows inserted
* @throws IOException
* if there were problems serializing the JobDataMap
*/
public int insertJobDetail(Connection conn, JobDetail job)
throws IOException, SQLException {
//log.debug( "Inserting JobDetail " + job );
ByteArrayOutputStream baos = serializeJobData(job.getJobDataMap());
int len = baos.toByteArray().length;
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
PreparedStatement ps = null;
int insertResult = 0;
try {
ps = conn.prepareStatement(rtp(INSERT_JOB_DETAIL));
ps.setString(1, job.getName());
ps.setString(2, job.getGroup());
ps.setString(3, job.getDescription());
ps.setString(4, job.getJobClass().getName());
setBoolean(ps, 5, job.isDurable());
setBoolean(ps, 6, job.isVolatile());
setBoolean(ps, 7, job.isStateful());
setBoolean(ps, 8, job.requestsRecovery());
ps.setBinaryStream(9, bais, len);
insertResult = ps.executeUpdate();
} finally {
closeStatement(ps);
}
if (insertResult > 0) {
String[] jobListeners = job.getJobListenerNames();
for (int i = 0; jobListeners != null && i < jobListeners.length; i++) {
insertJobListener(conn, job, jobListeners[i]);
}
}
return insertResult;
}
示例15: updateTrigger
import java.sql.PreparedStatement; //导入方法依赖的package包/类
public int updateTrigger(Connection conn, Trigger trigger, String state,
JobDetail jobDetail) throws SQLException, IOException {
ByteArrayOutputStream baos = serializeJobData(trigger.getJobDataMap());
int len = baos.toByteArray().length;
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
PreparedStatement ps = null;
int insertResult = 0;
try {
ps = conn.prepareStatement(rtp(UPDATE_TRIGGER));
ps.setString(1, trigger.getJobName());
ps.setString(2, trigger.getJobGroup());
setBoolean(ps, 3, trigger.isVolatile());
ps.setString(4, trigger.getDescription());
long nextFireTime = -1;
if (trigger.getNextFireTime() != null) {
nextFireTime = trigger.getNextFireTime().getTime();
}
ps.setBigDecimal(5, new BigDecimal(String.valueOf(nextFireTime)));
long prevFireTime = -1;
if (trigger.getPreviousFireTime() != null) {
prevFireTime = trigger.getPreviousFireTime().getTime();
}
ps.setBigDecimal(6, new BigDecimal(String.valueOf(prevFireTime)));
ps.setString(7, state);
if (trigger instanceof SimpleTrigger && ((SimpleTrigger)trigger).hasAdditionalProperties() == false ) {
// updateSimpleTrigger(conn, (SimpleTrigger)trigger);
ps.setString(8, TTYPE_SIMPLE);
} else if (trigger instanceof CronTrigger && ((CronTrigger)trigger).hasAdditionalProperties() == false ) {
// updateCronTrigger(conn, (CronTrigger)trigger);
ps.setString(8, TTYPE_CRON);
} else {
// updateBlobTrigger(conn, trigger);
ps.setString(8, TTYPE_BLOB);
}
ps.setBigDecimal(9, new BigDecimal(String.valueOf(trigger
.getStartTime().getTime())));
long endTime = 0;
if (trigger.getEndTime() != null) {
endTime = trigger.getEndTime().getTime();
}
ps.setBigDecimal(10, new BigDecimal(String.valueOf(endTime)));
ps.setString(11, trigger.getCalendarName());
ps.setInt(12, trigger.getMisfireInstruction());
ps.setInt(13, trigger.getPriority());
ps.setBinaryStream(14, bais, len);
ps.setString(15, trigger.getName());
ps.setString(16, trigger.getGroup());
insertResult = ps.executeUpdate();
} finally {
closeStatement(ps);
}
if (insertResult > 0) {
deleteTriggerListeners(conn, trigger.getName(), trigger.getGroup());
String[] trigListeners = trigger.getTriggerListenerNames();
for (int i = 0; trigListeners != null && i < trigListeners.length; i++) {
insertTriggerListener(conn, trigger, trigListeners[i]);
}
}
return insertResult;
}