【发布时间】:2015-08-02 02:51:34
【问题描述】:
我想显示/打印数据库中的 Blob 图像。使用以下代码,它只显示了这一点:
Pic: com.mysql.jdbc.Blob@1e1a68bc
Name:Test
Phone:1234
姓名和电话的正确数据有效,但 blob 不显示图像。我究竟做错了什么?有什么帮助吗?
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Test", "root", "");
stmt = conn.createStatement();
String query = "SELECT * FROM Person WHERE email ='"+emailLogin+"'";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String name = rs.getString("name");
String telephone = rs.getString("telephone");
Blob pic = rs.getBlob("foto");
out.print("Picture: "+pic + "<br>");
out.print("Name: "+name + "<br>");
out.print("Phone: "+telephone + "<br>");
}
} catch (SQLException e) {
out.println("An error occured while retrieving " + "all results: "
+ e.toString());
} catch (ClassNotFoundException e) {
throw (new ServletException(e.toString()));
} finally {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
}
}
【问题讨论】:
-
也许this answer 会有所帮助(即使是针对 Oracle 的)。