日期:2014-05-20  浏览次数:20778 次

显示数据库中image出错
String sql = "select image from t1 WHERE id=4"; 
String className = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://localhost:1433;databaseName=test1"; // 数据库名字
String user = "sa";
String pswd = "sa";
Class.forName(className);
Connection conn = DriverManager.getConnection(url, user, pswd);
PreparedStatement ps=conn.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
if(rs.next()) {
   [b] InputStream in = rs.getBinaryStream(1);   ServletOutputStream op = response.getOutputStream();
   int len;
   byte[] buf=new byte[1024];
   while((len= in.read(buf))!=-1) {
   op.write(buf, 0, len);
  in.read(buf);
   }
   op.close();
   in.close();
   }


在InputStream in = rs.getBinaryStream(1)时候出错?????

------解决方案--------------------
楼主把image以流的方式写到数据库? 存路径就可以了。何必这么麻烦