打印从DB中获取的图片

1。在应用程序中调用delegate 中的selectOneImage 方法 (注意: image: com.lowagie.text.image) 
byte[] byteImage = sdg.selectOneImage(query); 
Image image = null; 
if (byteImage != null && byteImage.length > 0){ 
image = Image.getInstance(byteImage); 
image.scaleAbsoluteHeight(80.0f); 
image.scaleAbsoluteWidth(320.0f); 
} 
2. delegate 中的selectOneImage 方法 
public byte[] selectOneImage(String query) { 
byte[] image = null; 
Connection conn = null; 
try { 
conn = ServiceLocator.getInstance().getDSDBConnection(); 
SelectDAO dao = new SelectDAO(); 
image = dao.selectOneImage(query, conn); 
} catch (Exception e) { 
Logger.logExceptions(this, e); 
} finally { 
try { 
if (conn != null) 
conn.close(); 
} catch (Exception e) { 
Logger.logExceptions(this, e); 
} 
} 
return image; 
} 
3。 SelectDao中的 selectOneImage方法 
public byte[] selectOneImage(String query, Connection conn) { 
Statement stmt = null; 
ResultSet rs = null; 
byte[] image = null; 

try { 
Logger.sql("select(), query=" + query); 
stmt = conn.createStatement(); 
rs = stmt.executeQuery(query); 
if (rs != null && rs.next()) { 
byte[] i = null; 
i = rs.getBytes(1); 
if (i == null) { 
image = null; 
} else { 
image = i; 
} 
} 
} catch (Exception e) { 
Logger.logExceptions(this, e); 
} finally { 
try { 
if (rs != null) 
rs.close(); 
if (stmt != null) 
stmt.close(); 
} catch (Exception e) { 
} 
} 
return image; 
} 

你可能感兴趣的:(DAO,sql)