我的数据库是SQLServer2000的,数据字段类型是image,里面保存了word,已经把word存到image字段里面了.就是不知道怎么读取然后显示在JSP页面上,请兄弟们帮忙解决.谢谢
<%@ page language="java" contentType="application/msword;charset=UTF-8" %>
<%@ page import="java.io.*,java.sql.*"%>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url = "jdbc:microsoft:sqlserver://192.168.1.101:1433;DatabaseName=wic";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(url, "sa", "sa");
stmt = con.createStatement();
String sql = "SELECT SSZS FROM SSJYB WHERE SSJYBH ='Z10-000001-1' AND YPMC='摆件'";
rs = stmt.executeQuery(sql);
response.setContentType("application/msword;charset=UTF-8");
while(rs.next()) {
InputStream in = rs.getBinaryStream("SSZS");
OutputStream ot=response.getOutputStream();
byte[] b = new byte[1024];
int len=0;
while((len=in.read(b,0,b.length))!=-1){
ot.write(b,0,len);
}
if(in!=null){
in.close();
}
if(ot!=null){
ot.close();
}
out.clear();
out = pageContext.pushBody();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (con != null) {
con.close();
}
}
%>
其中SSZS字段就是保存word文档的,SSZS是SQLServer2000的一个image类型的字段.现在就是读取不了,出现乱码.
换过编码了,还是不行.