【发布时间】:2016-03-22 03:16:12
【问题描述】:
当我运行这段代码时,
illegalException:: response getwriter() 已定义。
<%
Blob image = null;
Connection con = null;
byte[ ] imgData = null ;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hicheck","root","root");
stmt = con.createStatement();
String s="sivabrahma";
PreparedStatement ps=con.prepareStatement("select photo from hic_relation where email=? ");
ps.setString(1,"sivabrahma");
rs=ps.executeQuery();
if (rs.next()) {
image = rs.getBlob(1);
imgData = image.getBytes(1,(int)image.length());
}
else {
out.println("Display Blob Example");
out.println("image not found for given id");
return;
}
// display the image
response.setContentType("image/gif");
response.getOutputStream();
ServletOutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();
System.out.println(o.toString());
System.out.println(imgData.toString());
} catch (Exception e) {
out.println("Unable To Display image");
out.println("Image Display Error=" + e.getMessage());
// return;
} finally {
try {
rs.close();
stmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
} %>
当我从数据库中检索图像时发生异常。
【问题讨论】:
-
您的问题不准确。 1) 异常名称不正确。 2)从数据库中检索图像时没有发生异常:之后发生。此外,寻求 Java 异常帮助的问题应始终包含完整的堆栈跟踪。