⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 downloadpic.jsp

📁 jsp-公司管理系统-注册、会员管理等功能
💻 JSP
字号:
<%-- 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -