blogToString & stringToBlob

/**
  * transfer blob to string
  *
  * @param blob
  * @return string
  */
 private String blobToString(Blob blob) {

  try {
   byte[] compressed = blob.getBytes(1, (int) blob.length());
   byte[] uncompressed = Snappy.uncompress(compressed);
   String result = new String(uncompressed, "UTF-8");

   return result;
  } catch (Exception ex) {
   ex.printStackTrace();
  }
  return null;
 }

 /**
  * transfer string to blob
  *
  * @param tmp
  * @return blob
  */
 public Blob stringToBlob(String tmp) {
  try {
   byte[] b = Snappy.compress((tmp).getBytes("UTF-8"));
     return new javax.sql.rowset.serial.SerialBlob(b);
  } catch (Exception ex) {
   ex.printStackTrace();
  }

  return null;
 }

你可能感兴趣的:(toString)