作者:春暖花开时的夜晚 | 来源:互联网 | 2024-10-18 16:23
1
public static void writeImg(OutputStream os) {
2 Connection con;
3 try {
4 con =
ConnectionFactory.getConnection();
5 Statement stmt =
con.createStatement();
6 ResultSet rs = stmt.executeQuery("select pic from blob_table where b_id=1"
);
7 byte[] b =
new byte[1024
];
8 if (rs.next()) {
9 Blob blob = rs.getBlob(1
);
10 InputStream is =
blob.getBinaryStream();
11 int i = 0
;
12 while ((i = is.read(b)) != -1
) {
13 os.write(b, 0
, i);
14 }
15 os.close();
16 is.close();
17 }
18 rs.close();
19 stmt.close();
20 con.close();
21 }
catch (Exception e) {
22 e.printStackTrace();
23 }
24 }
然后做一个servlet,在doGet方法里调用writeImg方法
1 public void doGet(HttpServletRequest request, HttpServletResponse response)
2 throws ServletException, IOException {
3
4 DBOperator.writeImg(response.getOutputStream());
5
6 }
 
jsp代码:
<img&#160;src="servlet/newServlet"&#160;&#160;> &#160;
转载:作者longdick&#160; &#160; http://longdick.iteye.com
JSP读取Oracle数据库里的图片Blob字段并显示在页面上<转>
本文系统来源:http://www.cnblogs.com/wxm-bk/p/6580059.html
TAG标签: