當我從數據庫中讀取blob數據時,得到的值爲null
。什麼可能是這個問題?有人能幫助我嗎?getBinaryStream問題(索引)
Connection con = null;
PreparedStatement psStmt = null;
ResultSet rs = null;
try {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
con =
DriverManager.getConnection("jdbc:oracle:thin:@MyDatabase:1535:XE","password","password");
System.out.println("connection established"+con);
psStmt = con
.prepareStatement("Select Photo from Person where Firstname=?");
int i = 1;
psStmt.setLong(1, "Nani");
rs = null;
rs = psStmt.executeQuery();
InputStream inputStream = null;
while (rs.next()) {
inputStream = rs.getBinaryStream(1);
//Blob blob = rs.getBlob(1);
//Blob blob1 = (Blob)rs.getObject(1);
//System.out.println("blob length "+blob1);//rs.getString(1);
}
System.out.println("bytessssssss "+inputStream);//here i am getting null value.
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
感謝您的回答。我更新了我的問題,請通過。儘管我遇到了同樣的問題,但我已經完成了你所提到的任何事情。 – Nani 2014-09-29 08:13:12
@Nani可以更改InputStream inputStream = null;到InputStream inputStream = new InputStream()plz? – 2014-09-29 08:16:30
@Nani擺脫rs = null;在你的try catch塊內 – 2014-09-29 08:18:49