Converting in between Blob and StringBuilder

Reading Time: 1 minute

From StringBuilder to Blob

	private SessionFactory sessionFactory;

//saving the blob field
java.sql.Blob blob = org.hibernate.Hibernate.getLobCreator(sessionFactory.getCurrentSession()).createBlob(errorDescs.toString().getBytes());

From Blob to StringBuilder

StringBuilder errorDescs = new StringBuilder();
//error description
				if (order.getBatchErrorDescription() == null){
					errorDescs.append(response.getErrors().getDescription().toString() + ";");
					try {
						Blob blob = order.getBatchErrorDescription();
                                                 byte[] byteData = blob.getBytes(1, (int) blob.length());
						String data = new String(byteData);
								.append(response.getErrors().getDescription().toString() + ";");
					} catch (SQLException e) {
						LOG.error("error cannot retrieve data for error description column of an order id " + order.getOrderId());

Leave a Reply

Your email address will not be published. Required fields are marked *