【发布时间】:2014-04-04 01:50:25
【问题描述】:
我将 db 中的图像保存为 blob,我想检索图像并将其显示在浏览器中的 jsp 文件中。 我如何在 Java 中实现它? 谢谢
【问题讨论】:
-
你有没有尝试过或在谷歌上搜索?
-
如果你想要jsp代码或db代码。
我将 db 中的图像保存为 blob,我想检索图像并将其显示在浏览器中的 jsp 文件中。 我如何在 Java 中实现它? 谢谢
【问题讨论】:
试试这个方法,解决你的疑惑。
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();
另一个例子just goto this link
听我说,如果你有任何疑问,你应该给我cmets。
【讨论】: