<%@ page contentType="text/html;charset=GB2312"%>
<%@ page import="java.sql.*"%>
<%@page import="com.weboffice.util.DBManager"%>
<%@page import="com.weboffice.domain.TestTab"%>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
DBManager db=new DBManager();
try{
conn =db.getMysqlCon();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
} catch(SQLException e){
out.print("SQL异常:数据库连接关闭异常---" + e.getMessage());
}
String id = request.getParameter("id");
rs = stmt.executeQuery("select * from testtab where id=" + id);
while (rs.next()) {
try {
java.io.InputStream in = rs.getBinaryStream("proContent");
java.io.OutputStream outStream = response.getOutputStream();
byte[] buf = new byte[1024];
int bytes = 0;
while ((bytes = in.read(buf)) != -1)
outStream.write(buf, 0, bytes);
in.close();
outStream.close();
} catch (Throwable e) {
out.println(e.toString());
}
}
rs.close();
stmt.close();
conn.close();
%>数据中的proContent的类型是二进制 我现在要把二进制转行成String类型 这样写可以实现功能 但是我想把sql相关的东西放到数据访问层 我试过在数据访问层中返回resultset类型的方法 在把其他的代码放到Servlet中
这样做 不能实现 java.io.InputStream in = rs.getBinaryStream("proContent"); 这句代买中用了rs 该怎么做啊
???????????
如果这样,很难达到松耦合吧。