1
//when i display images in jsp page this error is showing...
//The image “http://localhost:8080/TestProject/blobrtv1.jsp?n=vipi” cannot be displayed
//because it contains errors.
//my code is below....
<%@page import="java.sql.*" %>
<%@page import="java.io.*" %>
<%!Connection con;
Statement stmt;
ResultSet rs7;%>
<% String name = request.getParameter("n");
out.println("Name" + name);
try
{
byte b;
byte imgData[] = null;
Blob image;
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/customer",
"root", "root");
stmt = con.createStatement();
rs7 = stmt.executeQuery("SELECT (cusPic) from cusinfo where cusName='" +
name + "'");
if (rs7.next())
{
out.println("cheking if loop\n");
image = rs7.getBlob(1);
out.println("\nImage is "+image);
imgData = image.getBytes(1, (int) image.length());
out.println("\nImgData is"+imgData);
} else
{
out.println("Display Blob Example");
out.println("image not found for given id>");
return;
}
// display the image
response.setContentType("image/jpg");
OutputStream o = response.getOutputStream();
o.write(imgData);
%>
<%
o.flush();
o.close();
} catch (Exception e)
{
out.println("Unable To Display image");
out.println("Image Display Error=" + e.getMessage());
return;
} finally
{
try
{
rs7.close();
stmt.close();
con.close();
} catch (SQLException e)
{
e.printStackTrace();
}
}
%>
が重複する可能性が...
私はそれを行うための正しい方法だと思いますMySQLから複数のイメージをrieve](http://stackoverflow.com/questions/2340406/retrieve-multiple-images-from-mysql) –