downloadpic.jsp

来自「jsp-公司管理系统-注册、会员管理等功能」· JSP 代码 · 共 50 行

JSP
50
字号
<%-- downLoadPic.jsp程序代码 --%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>

<%@ page import="java.io.InputStream" %>
<%@ page import="java.sql.SQLException" %>

<%
//建立数据库连接并执行图象数据查询

Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try{
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	conn=DriverManager.getConnection("jdbc:odbc:datasource_suit","sa","710318");
	String strSQL="select picture from t_picture";
	stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
	rs=stmt.executeQuery(strSQL);
	rs.last();  //将最后一张图片显示出来
	InputStream picIns=rs.getBinaryStream("picture");
	int picLength=10000; 
     	byte[] buf=new byte[10000]; //已限制图象大小
	response.setContentType("image/gif");
	ServletOutputStream sos= response.getOutputStream(); 
        picLength=picIns.read(buf,0,10000);
       	sos.write(buf,0,picLength);
	sos.close();
	picIns.close();
}catch(Exception e){
	out.println("获取图片二进制数据失败."+e.toString());
}
finally{
	try{
		if(rs!=null){
			rs.close();
		}
		if(stmt!=null){
			stmt.close();
		}
		if(conn!=null){
			conn.close();
		}
	}catch(SQLException e){}
}
		
%>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?