Here you can find the source of getStringValue(Blob blob)
Parameter | Description |
---|---|
blob | a parameter |
Parameter | Description |
---|---|
SQLException | an exception |
public static String getStringValue(Blob blob) throws SQLException
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.sql.Blob; import java.sql.Clob; import java.sql.SQLException; public class Main { /**//from w w w . j av a 2 s . co m * Return a string representation of an object * @param o * @return * @throws SQLException */ public static String getStringValue(Object o) throws SQLException { String s = null; if (o != null) { if (o instanceof Clob) { Clob clob = (Clob) o; s = clob.getSubString(1, (int) clob.length()); } else if (o instanceof String) { s = (String) o; } else { s = o.toString(); } } return s; } /** * Return a string representation of an object * @param blob * @return * @throws SQLException */ public static String getStringValue(Blob blob) throws SQLException { String s = null; InputStream is = null; if (blob != null) { is = blob.getBinaryStream(); } if (is != null) { BufferedInputStream bis = new BufferedInputStream(is, 4096); StringBuffer sb = new StringBuffer(); int ch = 0; try { while ((ch = bis.read()) != -1) { try { sb.append((char) ch); } catch (Exception e) { sb.append(' '); } } } catch (IOException e) { throw new SQLException(e.getMessage()); } s = sb.toString(); } return s; } }