<%@ page contentType="image/jpeg"%>
<%@ page
import="java.awt.image.*,java.sql.*,com.sun.image.codec.jpeg.*,java.util.*,javax.imageio.*,java.io.*"%>
<%
// Create image
String username, password, url;
Connection conn = null;
Statement stmt = null;
BufferedInputStream inputimage = null;
username = "username";
password = "password";
url = "jdbc:oracle:thin:@192.168.0.146:1521:orcl";
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, username, password);
stmt = conn.createStatement();
//boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
try {
ResultSet rs = stmt
.executeQuery("SELECT * FROM TEST_BLOB WHERE ID='111'");
while (rs.next()) {
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs
.getBlob("BLOBCOL");
inputimage = new BufferedInputStream(blob.getBinaryStream());
}
} catch (Exception ex) {
System.out.println("blobRead()'s exception" + ex);
conn.rollback();
throw ex;
}
//conn.setAutoCommit(defaultCommit);
// Send back image
BufferedImage image = null;
try {
image = ImageIO.read(inputimage);
} catch (IOException e) {
System.out.println(e);
}
ServletOutputStream sos = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);
encoder.encode(image);
inputimage.close();
%>
jsp blob
最新推荐文章于 2020-04-22 15:38:58 发布