我把我以前收集的给你贴出来,希望能对你有所帮助
jsp编程从数据库中取出图片
1、读取图片数据testimageout.jsp文件
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:denglu","sa","sa");
Statement stmt=con.createStatement();
ResultSet rs=null;
int id=Integer.parseInt(request.getParameter("id"));
String sql = "select image from picturenews where id='"+id+"'";
rs=stmt.executeQuery(sql);
while(rs.next())
{
ServletOutputStream sout = response.getOutputStream();
InputStream in = rs.getBinaryStream(1);
byte b[] = new byte[0x7a120];
for(int i = in.read(b);i!=-1)
{
sout.write(b);
in.read(b);
}
sout.flush();
sout.close();
}
%>
2、取出所要显示的图片showimage.jsp文件
显示数据库图片测试页Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:denglu","sa","sa");
Statement stmt=con.createStatement();
String sql=new String();
sql = "select id from picturenews";
ResultSet rs=stmt.executeQuery(sql);
//显示最后一条记录的图片
rs.last();
%>
取消
评论