Java Code Examples for java.sql.PreparedStatement.setCharacterStream()

The following are Jave code examples for showing how to use setCharacterStream() of the java.sql.PreparedStatement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: jaffa-framework   File: TypeDefs.java   Source Code and License Vote up 7 votes
/** 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 String))
            value = DataTypeMapper.instance().map(value, String.class);
        if ("oracle".equalsIgnoreCase(engineType) && !supportsStdLob(pstmt)) {
            Clob clob = createClob(pstmt.getConnection(), (String) value);
            pstmt.setClob(parameterIndex, clob);
        } else {
            String str = (String) value;
            Reader reader = new BufferedReader(new StringReader(str));
            pstmt.setCharacterStream(parameterIndex, reader, str.length());
        }
    } else
        pstmt.setNull(parameterIndex, getSqlType(Defaults.CLOB, engineType));
}
 
Example 2
Project: lams   File: DefaultLobHandler.java   Source Code and License Vote up 6 votes
@Override
public void setClobAsCharacterStream(
		PreparedStatement ps, int paramIndex, Reader characterStream, int contentLength)
		throws SQLException {

	if (streamAsLob) {
		if (characterStream != null) {
			ps.setClob(paramIndex, characterStream, contentLength);
		}
		else {
			ps.setClob(paramIndex, (Clob) null);
		}
	}
	else if (wrapAsLob) {
		if (characterStream != null) {
			ps.setClob(paramIndex, new PassThroughClob(characterStream, contentLength));
		}
		else {
			ps.setClob(paramIndex, (Clob) null);
		}
	}
	else {
		ps.setCharacterStream(paramIndex, characterStream, contentLength);
	}
	if (logger.isDebugEnabled()) {
		logger.debug(characterStream != null ? "Set character stream for CLOB with length " + contentLength :
				"Set CLOB to null");
	}
}
 
Example 3
Project: lams   File: AbstractHANADialect.java   Source Code and License Vote up 6 votes
@Override
public <X> BasicBinder<X> getClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
	return new BasicBinder<X>( javaTypeDescriptor, this ) {
		@Override
		protected void doBind(final PreparedStatement st, final X value, final int index,
				final WrapperOptions options) throws SQLException {
			final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class,
					options );

			if ( value instanceof ClobImplementer ) {
				st.setCharacterStream( index, new CloseSuppressingReader( characterStream.asReader() ),
						characterStream.getLength() );
			}
			else {
				st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() );
			}

		}
	};
}
 
Example 4
Project: lams   File: AbstractHANADialect.java   Source Code and License Vote up 6 votes
@Override
public <X> BasicBinder<X> getNClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
	return new BasicBinder<X>( javaTypeDescriptor, this ) {
		@Override
		protected void doBind(final PreparedStatement st, final X value, final int index,
				final WrapperOptions options) throws SQLException {
			final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class,
					options );

			if ( value instanceof NClobImplementer ) {
				st.setCharacterStream( index, new CloseSuppressingReader( characterStream.asReader() ),
						characterStream.getLength() );
			}
			else {
				st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() );
			}

		}
	};
}
 
Example 5
Project: Equella   File: ImmutableHibernateXStreamType.java   Source Code and License Vote up 5 votes
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index) throws SQLException
{
	if( value != null )
	{
		String string = xstream.serialiseToXml(value);
		StringReader reader = new StringReader(string);
		st.setCharacterStream(index, reader, string.length());
	}
	else
	{
		st.setNull(index, sqlTypes()[0]);
	}
}
 
Example 6
Project: lams   File: StringClobType.java   Source Code and License Vote up 5 votes
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
	if ( value != null ) {
		String string = (String) value;
		StringReader reader = new StringReader( string );
		st.setCharacterStream( index, reader, string.length() );
	}
	else {
		st.setNull( index, sqlTypes()[0] );
	}
}
 
Example 7
Project: lams   File: ClobTypeDescriptor.java   Source Code and License Vote up 5 votes
@Override
            public <X> BasicBinder<X> getClobBinder(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 CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options );
			st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() );
		}
	};
}
 
Example 8
Project: lams   File: ClobTypeDescriptor.java   Source Code and License Vote up 5 votes
@Override
            public <X> BasicBinder<X> getClobBinder(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 CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options );
			st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() );
		}
	};
}
 
Example 9
Project: lams   File: NClobTypeDescriptor.java   Source Code and License Vote up 5 votes
@Override
            public <X> BasicBinder<X> getNClobBinder(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 CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options );
			st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() );
		}
	};
}
 
Example 10
Project: unitimes   File: XmlClobType.java   Source Code and License Vote up 5 votes
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(bytes,OutputFormat.createCompactFormat());
            writer.write((Document)value);
            writer.flush(); writer.close();
            ps.setCharacterStream(index, new CharArrayReader(bytes.toString().toCharArray(),0,bytes.size()), bytes.size());
        } catch (IOException e) {
            throw new HibernateException(e.getMessage(),e);
        }
    }
}
 
Example 11
Project: uroborosql   File: ReaderParameter.java   Source Code and License Vote up 5 votes
/**
 * ステートメントにストリームパラメータを登録。
 *
 * @param preparedStatement ステートメント
 * @param index パラメータインデックス
 * @return 次のパラメータインデックス
 * @throws SQLException SQL例外
 */
protected int setReaderParameter(final PreparedStatement preparedStatement, int index) throws SQLException {
	if (len > -1) {
		preparedStatement.setCharacterStream(index, reader, len);
	} else {
		preparedStatement.setCharacterStream(index, reader);
	}
	parameterLog(index);
	index++;

	return index;
}
 
Example 12
Project: jaffa-framework   File: Wrapper.java   Source Code and License Vote up 5 votes
private void addToPartRem(Connection connection)
throws SQLException {
    //String sql = "insert into ZZ_JUT_PART_REM VALUES('Z-TESTPART-01', 'SOME REMARKS'";
    //executeSql(connection, sql);

    // the following is needed, since jdbc requires that fields having 4000+ characters be passed in via streams
    String sql = "insert into ZZ_JUT_PART_REM VALUES(?,?)";
    PreparedStatement pstmnt = connection.prepareStatement(sql);
    pstmnt.setString(1, "Z-TESTPART-01");
    pstmnt.setCharacterStream(2, new BufferedReader(new StringReader(CATZ_REMARKS)), CATZ_REMARKS.length());
    pstmnt.execute();
    pstmnt.close();
}
 
Example 13
Project: jaffa-framework   File: TypeDefs.java   Source Code and License Vote up 5 votes
/** 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 String))
            value = DataTypeMapper.instance().map(value, String.class);
        String str = (String) value;
        Reader reader = new BufferedReader(new StringReader(str));
        pstmt.setCharacterStream(parameterIndex, reader, str.length());
    } else
        pstmt.setNull(parameterIndex, getSqlType(Defaults.LONG_STRING, engineType));
}
 
Example 14
Project: lams   File: AbstractLongStringType.java   Source Code and License Vote up 4 votes
public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
	String str = (String) value;
	st.setCharacterStream( index, new StringReader(str), str.length() );
}
 
Example 15
Project: lams   File: AbstractCharArrayType.java   Source Code and License Vote up 4 votes
public void set(PreparedStatement st, Object value, int index) throws SQLException {
	char[] chars = toInternalFormat( value );
	st.setCharacterStream(index, new CharArrayReader(chars), chars.length);
}
 
Example 16
Project: tangyuan2   File: ClobTypeHandler.java   Source Code and License Vote up 4 votes
@Override
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
	StringReader reader = new StringReader(parameter);
	ps.setCharacterStream(i, reader, parameter.length());
}
 
Example 17
Project: tangyuan2   File: NClobTypeHandler.java   Source Code and License Vote up 4 votes
@Override
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
	StringReader reader = new StringReader(parameter);
	ps.setCharacterStream(i, reader, parameter.length());
}