如何在数据库中显示存储为blob的图像?

时间:2018-04-16 18:16:56

标签: java mysql jsp

这是我的数据库数据检索代码,这只能检索String数据,但我也想显示图像。怎么做?

    <%
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/distributed","root","");
            statement = connection.createStatement();
            String sql = "select * from product where id = '1'";
            resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
    %>

        <h3><%=resultSet.getString("name")%></h3>
        <%=resultSet.getString("cost")%>
        <%=resultSet.getString("description")%>




    <%
        }
            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    %>

1 个答案:

答案 0 :(得分:0)

如果您在数据库中有用于存储图像和音频等文件的字段。您应该使用BLOB数据类型。

Here's an example of retrieving images from database