lorcx935200
2016-01-13 13:50
采纳率: 46.7%
浏览 2.9k
已采纳

jsp 输出图片 blob.getBytes()问题

    response.setContentType("image/jpeg");
String userName = request.getParameter("userName");
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
Connection conn = DriverManager.getConnection(url,"llxx","lorcx");
StringBuilder sql = new StringBuilder();
sql.append("select u.pic from base_user u where u.user_name = '").append(userName).append("'");
PreparedStatement ps = conn.prepareStatement(sql.toString());
ResultSet rs = ps.executeQuery();
if(rs != null){
  while (rs.next()){
    Blob blob = rs.getBlob(1);//获取文件
    int size = (int)blob.length();
    byte[] b = blob.getBytes(1,size);
    ServletOutputStream os = response.getOutputStream();
    os.write(b);
    os.flush();
    os.close();
  }
}

    我在调用getBytes时开始位置是1才能显示,为什么不是0
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题