Java-显示从浏览器中的数据库检索到的图像 [英] Java -Display image that retrieved from DB in browser
本文介绍了Java-显示从浏览器中的数据库检索到的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在db中将图像另存为blob,我想检索图像并将其显示在浏览器中的jsp文件中. 我如何在Java中实现它? 谢谢
I save images in db as blobs and I want to retrieve an image and display it in browser in jsp file. How I implement it in Java ? Thanks
推荐答案
尝试此方法并解决您的疑问.
try this method and solve your doubts.
Connection connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT col_blob FROM mysql_all_table");
if (rs.next()) {
Blob blob = rs.getBlob("col_blob");
long blobLength = blob.length();
int pos = 1; // position is 1-based
int len = 10;
byte[] bytes = blob.getBytes(pos, len);
InputStream is = blob.getBinaryStream();
int b = is.read();
另一个示例只需转到此链接
听我说,如果您有任何疑问,必须给我评论.
listen to me, if you had any doubt you should must give me comments.
这篇关于Java-显示从浏览器中的数据库检索到的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文