2017-01-18 8 views
1

のJava 1.7は、Apache POI--3.8、JDBCApache-poiブックオブジェクトをOracle BLOB列に格納する/取り出しする方法

要件: 1)サーバーの任意のファイル作成.without DBから来ている完全なデータを持つワークブックオブジェクトを()を作成します。エラーを取得取得中

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. 

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)

// TODO How to retrive 

するアプローチに続いてブロブからのデータ(ワークブック)を取得し、Excelにこれを変換し、メールの添付ファイルに送りますファイルが壊れた。

答えて

1

あなたは、あなたの場合には、それはむしろする必要がありますので、ストリーム内の適切なバイト数を設定する必要があります。

byte[] byteArray = wb.getBytes(); 
ps.setBinaryStream(1, new ByteArrayInputStream(byteArray), byteArray.length); 
... 

その後InputStream使用getBinaryStream(String columnLabel)またはgetBinaryStream(int columnIndex)としてあなたの列のコンテンツを取得します。

+1

true :)私は長さ1000000を与えていました。そのため、ファイルが壊れていたためです。 – user3676578

関連する問題