Java-在浏览器中从DB检索的显示图像

时间:2014-03-03 05:49:10

标签: java jsp

我将数据库中的图像保存为blob,我想检索图像并在浏览器中以jsp文件显示它。 我是如何用Java实现的? 谢谢

1 个答案:

答案 0 :(得分:0)

尝试这种方法并解决您的疑虑。

    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

的另一个例子

听我说,如果你有任何疑问,你应该给我评论。