嗨,我是使用下面的代碼來檢索來自PostgreSQL文件BYTEA使用Java, 但裏面的文件我得到號碼,如314530413142313141用java
File file = new File("c:/test.doc");
FileOutputStream fos = new FileOutputStream(file);
ResultSet rs = st.executeQuery("SELECT * FROM test_bytea where id=" + 1);
if (rs != null) {
while (rs.next()) {
byte[] fileBytes = new byte[1024];
InputStream is = rs.getBinaryStream("type_file");
while (is.read(fileBytes) > 0) {
fos.write(fileBytes);
}
// use the stream in some way here
}
rs.close();
}
檢索從BYTEA文件中PostgreSQL的請讓我知道我的代碼中出了什麼問題?
你** **絕對肯定'type_file'的類型爲'bytea'?您描述的行爲聽起來像列被定義爲'oid' –
是的100%確定type_file是bytea數據類型的cloumn名稱 – Sathish
[如何使用Java下載bytea列作爲文件](http:// stackoverflow.com/questions/33107318/how-to-download-bytea-column-as-file-using-java) –