日期:2014-05-18  浏览次数:20732 次

help me !jsp中怎么读取mysql中的text 和blob类型字段???
小弟我刚学jsp和mysql没几天,请问高手怎样在jsp页面中读取mysql中的text,blob类型字段啊!

------解决方案--------------------
java.sql.Connection conn;
ResultSet rs=null;
Class.forName( "org.gjt.mm.mysql.Driver ").newInstance();
conn= java.sql.DriverManager.getConnection( "jdbc:mysql://localhost/test ", "root ", " ");
Statement stmt=conn.createStatement();
rs=stmt.executeQuery( "select * from test where id= '1 ' ");
if(rs.next())
{
Blob b = rs.getBlob( "pic ");

int size =(int)b.length();
out.print(size);
InputStream in=b.getBinaryStream();
byte[] by= new byte[size];
response.setContentType( "image/jpeg ");
ServletOutputStream sos = response.getOutputStream();
int bytesRead = 0;
while ((bytesRead = in.read(by)) != -1) {
sos.write(by, 0, bytesRead);
}
in.close();
sos.flush();

}