mysql 取 第一张 图片_MyEclipse------从MySQL取出图片

Stringpath=request.getContextPath();StringbasePath=request.getScheme()+ "://"

+request.getServerName()+ ":" +request.getServerPort()+path+ "/";%>

">

My JSP 'showImage.jsp' starting page

Stringurl="jdbc:mysql://localhost:3306/student?useSSL=true";StringuseName="root";Stringpassword="2277092";Stringsql="select binfile from bindata where name='01'";

try{

Class.forName("com.mysql.jdbc.Driver");

}

catch(Exception e){

out.print(e);

}

Connection conn=null;//连接数据库

Statement stmt=null;//执行SQL语句

ResultSet rs=null;//取得结果集

conn=DriverManager.getConnection(url,useName,password);

try{

stmt=conn.createStatement();

rs=stmt.executeQuery(sql);

}catch(SQLException e){

out.print(e);

}

try{while(rs.next()){

response.setContentType("image/jpeg");//设置返回给客户端的内容的类型//给客户端提供一个输出二进制的输出流

ServletOutputStream sout=response.getOutputStream();

InputStream in=rs.getBinaryStream(1);byteb[]=new byte[0x7a120];for(inti=in.read(b);i!=-1;){

sout.write(b);

in.read();

}

sout.flush();

sout.close();

}

out.clear();

out=pageContext.pushBody();

}

catch(Exception e){

out.print(e);

}%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值