List of usage examples for java.sql Blob getBytes
byte[] getBytes(long pos, int length) throws SQLException;
From source file:com.pari.nm.utils.db.InventoryDBHelper.java
public static String getShowCli(int nodeId, String cli) { ResultSet rs = null;/*from w ww.j ava 2 s . c o m*/ Connection c = null; PreparedStatement ps = null; String sql = "select out_put from show_commands_new where device_id=? and cli=?"; try { c = DBHelper.getConnection(); ps = c.prepareStatement(sql); ps.setInt(1, nodeId); ps.setString(2, cli); rs = ps.executeQuery(); byte b[] = null; if (rs != null && rs.next()) { if (ServerProperties.getInstance().isPostgres()) { b = rs.getBytes(1); } else { Blob blob = rs.getBlob(1); if (blob != null) { b = blob.getBytes(1, (int) blob.length()); } } if (b != null) { return CompressionUtils.getUncompressedString(b); } } } catch (Exception ee) { logger.warn("Error while getting show cli for the node = " + nodeId + " and cli = " + cli, ee); } finally { if (rs != null) { try { rs.close(); } catch (Exception ex) { } } if (ps != null) { try { ps.close(); } catch (Exception ee) { } } if (c != null) { try { DBHelper.releaseConnection(c); } catch (Exception ex) { } } } return ""; }