Java Code Examples for java.sql.ResultSet.getCharacterStream()

The following are Jave code examples for showing how to use getCharacterStream() of the java.sql.ResultSet 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 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);
	}
}
 
Example 2
Project: Equella   File: ImmutableHibernateXStreamType.java   View Source Code Vote up 5 votes
@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);
}
 
Example 3
Project: lams   File: AbstractLongStringType.java   View Source Code Vote up 5 votes
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();
	}
 
Example 4
Project: lams   File: AbstractCharArrayType.java   View Source Code Vote up 5 votes
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");
		}
	}
}
 
Example 5
Project: lams   File: StringClobType.java   View Source Code Vote up 5 votes
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();
}
 
Example 6
Project: calcite-avatica   File: AvaticaResultSetConversionsTest.java   View Source Code Vote up 5 votes
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
  }
}
 
Example 7
Project: aceql-http   File: ResultSetWriter.java   View Source Code Vote up 4 votes
/**
    * 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;
   }