When I read an image from database, it appears in the JLabel
immediately, but it takes too much time to complete streaming the BLOB
from the DB.
public byte[] selectImage(int Id) throws SQLException {
ResultSet res=null;
int c=0;
try {
Class.forName(driver);
con = DriverManager.getConnection(connectionURL);
} catch (SQLException ex) {
Logger.getLogger(Connect.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Connect.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(con.getAutoCommit());
statement = con.createStatement() ;
res = statement.executeQuery("SELECT PHOTO FROM CUSTOMER where ID="+Id) ;
while(res.next() && (res!=null)) {
Blob bodyOut = res.getBlob("PHOTO");
int length = (int) bodyOut.length();
System.out.println(" Body Size = "+length);
imageBytes = bodyOut.getBytes(1, length);
bodyOut.free();
}
return imageBytes;
}