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

The following are Jave code examples for showing how to use setAsciiStream() 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.
+ Save this method
Example 1
Project: lams   File: DefaultLobHandler.java   View Source Code Vote up 6 votes
@Override
public void setClobAsAsciiStream(
		PreparedStatement ps, int paramIndex, InputStream asciiStream, int contentLength)
		throws SQLException {

	if (streamAsLob) {
		if (asciiStream != null) {
			try {
				ps.setClob(paramIndex, new InputStreamReader(asciiStream, "US-ASCII"), contentLength);
			}
			catch (UnsupportedEncodingException ex) {
				throw new SQLException("US-ASCII encoding not supported: " + ex);
			}
		}
		else {
			ps.setClob(paramIndex, (Clob) null);
		}
	}
	else if (wrapAsLob) {
		if (asciiStream != null) {
			ps.setClob(paramIndex, new PassThroughClob(asciiStream, contentLength));
		}
		else {
			ps.setClob(paramIndex, (Clob) null);
		}
	}
	else {
		ps.setAsciiStream(paramIndex, asciiStream, contentLength);
	}
	if (logger.isDebugEnabled()) {
		logger.debug(asciiStream != null ? "Set ASCII stream for CLOB with length " + contentLength :
				"Set CLOB to null");
	}
}
 
Example 2
Project: uroborosql   File: StreamParameter.java   View Source Code Vote up 6 votes
/**
 * ステートメントにストリームパラメータを登録。
 *
 * @param preparedStatement ステートメント
 * @param index パラメータインデックス
 * @param parameterMapperManager パラメータ変換管理クラス
 * @return 次のパラメータインデックス
 * @throws SQLException SQL例外
 */
protected int setStreamParameter(final PreparedStatement preparedStatement, int index,
		final BindParameterMapperManager parameterMapperManager) throws SQLException {

	if (Objects.equals(sqlType, JDBCType.BLOB)) {
		if (len > -1) {
			preparedStatement.setBinaryStream(index, stream, len);
		} else {
			preparedStatement.setBinaryStream(index, stream);
		}
	} else if (Objects.equals(sqlType, JDBCType.CLOB)) {
		if (len > -1) {
			preparedStatement.setAsciiStream(index, stream, len);
		} else {
			preparedStatement.setAsciiStream(index, stream);
		}
	} else {
		return super.setParameter(preparedStatement, index, parameterMapperManager);
	}

	parameterLog(index);
	index++;

	return index;
}