Java 1.7, Apache-poi-3.8, JDBC
Requirements : 1) Create a workbook object with full data (which is coming from the DB).without any file creation at server.
HSSFWorkbook wb = new HSSFWorkbook(); // this object I want to store in DB blob column, without any file creation at server.
insertDataToCells(wb, "output", data); // this method will insert data in cells of workbook.
**//TODO code to store wb in blob column.** // How to store ?
2) Retrieve the data(workbook) from blob and convert this into excel and send into mail attachment
// TODO How to retrive
Following Approach :
byte[] byteArray = wb.getBytes();
InputStream is = new ByteArrayInputStream(byteArray);
ps.setBinaryStream(1, is, 1000000); // Here i am having some confusion
ps.execute // Successfully stored in blob column.
While retrieving getting error file corrupted.
You need to set properly the number of bytes in the stream so in your case it should rather be:
byte[] byteArray = wb.getBytes();
ps.setBinaryStream(1, new ByteArrayInputStream(byteArray), byteArray.length);
...
Then to retrieve the content of your column as an InputStream
use getBinaryStream(String columnLabel)
or getBinaryStream(int columnIndex)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.