本文整理汇总了Java中java.sql.ResultSet.getCharacterStream方法的典型用法代码示例。如果您正苦于以下问题:Java ResultSet.getCharacterStream方法的具体用法?Java ResultSet.getCharacterStream怎么用?Java ResultSet.getCharacterStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.ResultSet
的用法示例。
在下文中一共展示了ResultSet.getCharacterStream方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClobAsCharacterStream
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public Reader getClobAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException {
logger.debug("Returning CLOB as character stream");
if (this.wrapAsLob) {
Clob clob = rs.getClob(columnIndex);
return clob.getCharacterStream();
}
else {
return rs.getCharacterStream(columnIndex);
}
}
示例2: nullSafeGet
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws SQLException
{
Reader reader = rs.getCharacterStream(names[0]);
if( reader == null )
{
return null;
}
StringBuilder result = new StringBuilder(4096);
try
{
char[] charbuf = new char[4096];
for( int i = reader.read(charbuf); i > 0; i = reader.read(charbuf) )
{
result.append(charbuf, 0, i);
}
}
catch( IOException e )
{
throw new SQLException(e.getMessage());
}
// wtf??
String xml = result.toString();
if( xml.trim().length() == 0 )
{
return null;
}
return xstream.deserialiseFromXml(getClass().getClassLoader(), xml);
}
示例3: get
import java.sql.ResultSet; //导入方法依赖的package包/类
public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
// Retrieve the value of the designated column in the current row of this
// ResultSet object as a java.io.Reader object
Reader charReader = rs.getCharacterStream(name);
// if the corresponding SQL value is NULL, the reader we got is NULL as well
if (charReader==null) return null;
// Fetch Reader content up to the end - and put characters in a StringBuilder
StringBuilder sb = new StringBuilder();
try {
char[] buffer = new char[2048];
while (true) {
int amountRead = charReader.read(buffer, 0, buffer.length);
if ( amountRead == -1 ) break;
sb.append(buffer, 0, amountRead);
}
}
catch (IOException ioe) {
throw new HibernateException( "IOException occurred reading text", ioe );
}
finally {
try {
charReader.close();
}
catch (IOException e) {
throw new HibernateException( "IOException occurred closing stream", e );
}
}
// Return StringBuilder content as a large String
return sb.toString();
}
示例4: get
import java.sql.ResultSet; //导入方法依赖的package包/类
public Object get(ResultSet rs, String name) throws SQLException {
Reader stream = rs.getCharacterStream(name);
if ( stream == null ) return toExternalFormat( null );
CharArrayWriter writer = new CharArrayWriter();
for(;;) {
try {
int c = stream.read();
if ( c == -1) return toExternalFormat( writer.toCharArray() );
writer.write( c );
}
catch (IOException e) {
throw new HibernateException("Unable to read character stream from rs");
}
}
}
示例5: nullSafeGet
import java.sql.ResultSet; //导入方法依赖的package包/类
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
Reader reader = rs.getCharacterStream( names[0] );
if ( reader == null ) return null;
StringBuilder result = new StringBuilder( 4096 );
try {
char[] charbuf = new char[4096];
for ( int i = reader.read( charbuf ); i > 0 ; i = reader.read( charbuf ) ) {
result.append( charbuf, 0, i );
}
}
catch (IOException e) {
throw new SQLException( e.getMessage() );
}
return result.toString();
}
示例6: testGetCharacterStream
import java.sql.ResultSet; //导入方法依赖的package包/类
public void testGetCharacterStream(ResultSet resultSet) throws SQLException {
try {
resultSet.getCharacterStream(ordinal);
fail("Was expecting to throw SQLDataException");
} catch (Exception e) {
assertThat(e, isA((Class) SQLDataException.class)); // success
}
}
示例7: formatClobColumn
import java.sql.ResultSet; //导入方法依赖的package包/类
/**
* the CLOB content is dumped in a server file that will be available for
* the client the name of the file will be stored in the output stream ;
*
* @param resultSet
* the result set in progress to send back to the client side
* @param columnIndex
* the column index
*
* @return the formated binary column
*
* @throws SQLException
*/
private String formatClobColumn(ResultSet resultSet, int columnIndex)
throws SQLException, IOException {
String columnValueStr;
String fileName = FrameworkFileUtil.getUniqueId() + ".clob.txt";
// Maybe null, we want to keep the info
Reader reader = resultSet.getCharacterStream(columnIndex);
BufferedReader br = new BufferedReader(reader);
String hostFileName = null;
// hostFileName = HttpConfigurationUtil.addRootPath(fileConfigurator,
// username, fileName);
String database = request.getParameter(HttpParameter.DATABASE);
DatabaseConfigurator databaseConfigurator = ServerSqlManager
.getDatabaseConfigurator(database);
hostFileName = databaseConfigurator.getBlobsDirectory(username)
+ File.separator + fileName;
debug("formatClobColumn:writer: " + hostFileName);
if (reader == null) {
try (Writer writer = new BufferedWriter(
new FileWriter(hostFileName));) {
debug("formatClobColumn.reader == null");
writer.write(NULL_STREAM + CR_LF);
}
} else {
writeClobFile(br, hostFileName);
}
// The column value is a file name with a tag for identification
columnValueStr = fileName;
return columnValueStr;
}