List of usage examples for java.sql ResultSet getAsciiStream
java.io.InputStream getAsciiStream(String columnLabel) throws SQLException;
ResultSet
object as a stream of ASCII characters. From source file:org.jiemamy.utils.sql.ResultSetUtil.java
/** * {@link ResultSet#getAsciiStream(String)}?????????? * ??????? {@link SQLException}??????{@code defaultValue}? * // ww w . j a v a 2 s. c om * <p>{@link #getValue(Class, ResultSet, String, Object)}??{@link ResultSet#getBinaryStream(String)}? * ???????????</p> * * @param rs {@link ResultSet} * @param columnName ?? * @param defaultValue {@link SQLException}??????getter???????? * @return ??????? * @throws IllegalArgumentException {@code rs}?{@code null}??? */ public static InputStream getAsciiStream(ResultSet rs, String columnName, InputStream defaultValue) { Validate.notNull(rs); try { return rs.getAsciiStream(columnName); } catch (SQLException e) { // ignore } return defaultValue; }
From source file:org.kawanfw.test.api.client.InsertAndUpdateClobTestAsciiStream.java
/** * Test that the blob was were correctly inserted * /*from w w w.j a v a2s. c o m*/ * @param connection */ public void selectClobTest(Connection connection, String originalFileName, String shaHexa) throws Exception { int item_id; String sql = "select * from documentation where item_id >= ? "; PreparedStatement prepStatement = connection.prepareStatement(sql); int i = 1; prepStatement.setInt(i++, 1); ResultSet rs = prepStatement.executeQuery(); MessageDisplayer.display(""); InputStream in = null; Writer writer = null; while (rs.next()) { item_id = rs.getInt("item_id"); File originalFile = SqlTestParms.getFileFromUserHome(originalFileName); // String extension = "." // + StringUtils.substringAfterLast(originalFile.toString(), // "."); File file = InsertAndUpdateBlobTest.createTempFile(originalFile.toString()); MessageDisplayer.display("file: " + file); try { in = rs.getAsciiStream("item_doc"); if (in != null) { Reader reader = new InputStreamReader(in); writer = new BufferedWriter(new FileWriter(file)); IOUtils.copy(reader, writer); } else { MessageDisplayer.display("item_doc column is null!"); } } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(writer); } i = 1; item_id = rs.getInt(i++); MessageDisplayer.display(""); MessageDisplayer.display("item_id : " + item_id); // Compute the hash of the file Sha1Util sha1 = new Sha1Util(); String shaHexaNew = sha1.getHexFileHash(file); Assert.assertEquals("Comparing original " + SqlTestParms.TEXT_FILE_1 + " new " + file + " hash values ", shaHexa, shaHexaNew); file.delete(); MessageDisplayer.display(""); MessageDisplayer.display("Ok, SHA-1 value of read file " + file + " is same as inserted file " + SqlTestParms.getFileFromUserHome(originalFileName)); } prepStatement.close(); rs.close(); MessageDisplayer.display("Select done!"); }
From source file:org.seasar.s2sqlmap.spring.lob.port.DefaultLobHandler.java
public InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex) throws SQLException { logger.debug("Returning CLOB as ASCII stream"); return rs.getAsciiStream(columnIndex); }
From source file:org.springframework.jdbc.support.lob.DefaultLobHandler.java
@Override public InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex) throws SQLException { logger.debug("Returning CLOB as ASCII stream"); if (this.wrapAsLob) { Clob clob = rs.getClob(columnIndex); return clob.getAsciiStream(); } else {/*from w w w. j a v a 2s . c o m*/ return rs.getAsciiStream(columnIndex); } }
From source file:org.squale.welcom.outils.jdbc.wrapper.ResultSetUtils.java
/** * Populate the properties of the specified JavaBean from the next record of the specified ResultSet, based on * matching each column name against the corresponding JavaBeans "property setter" methods in the bean's class. * Suitable conversion is done for argument types as described under <code>convert()</code>. * // w ww .j a va 2s . com * @param bean The JavaBean whose properties are to be set * @param resultSet The ResultSet whose parameters are to be used to populate bean properties * @exception SQLException if an exception is thrown while setting property values or access the ResultSet */ public static void populate(final Object bean, final ResultSet resultSet) throws SQLException { // Format pour les dates final SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy HH:mm"); // Build a list of relevant column properties from this resultSet final HashMap properties = new HashMap(); // Acquire resultSet MetaData final ResultSetMetaData metaData = resultSet.getMetaData(); final int cols = metaData.getColumnCount(); // Scroll to next record and pump into hashmap // if (resultSet.next()) for (int i = 1; i <= cols; i++) { if (metaData.getColumnClassName(i).equals("java.sql.Timestamp")) { properties.put(metaData.getColumnName(i), getFormattedDateTimeColumn(resultSet.getTimestamp(i), formatDate)); } else if (metaData.getColumnClassName(i).equals("oracle.sql.CLOB")) { properties.put(metaData.getColumnName(i), getFormattedClobColumn(resultSet.getAsciiStream(i))); } else { properties.put(metaData.getColumnName(i), getFormattedStringColumn(resultSet.getString(i))); } } // Set the corresponding properties of our bean try { populateIgnoreCase(bean, properties); } catch (final Exception e) { throw new SQLException("BeanUtils.populate threw " + e.toString()); } }