请问mssql2000的img图像类型的数据如何在web页面上显示? SQL Server 2000的img类型存储的是图片,可是用PHP无法在网页上显示,显示出来的是乱码,img格式的记录,是以二进制的方式保存在数据库里的。不知道有没有很好的方法能够将数据库的图片记录显示在网页上,或者将图片记录转成图片也行。希望给予指点,谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 // 从表中得到照片到页面 public ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { PreparedStatement pst = null; Connection m_conn=null; try { Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test"; m_conn = DriverManager.getConnection(url, "sa", "1234"); String sql = "select pic from picture where id=" + 1; pst = m_conn.prepareStatement(sql); ResultSet rs = pst.executeQuery(); if (rs.next()) { InputStream in = rs.getBinaryStream("pic");//表中图片类型的字段名 int bytesRead = 0; byte[] buffer = new byte[8192]; //设置照片格式. response.setContentType("image/gif"); //返回ServletOutputStream 对象. OutputStream outs = response.getOutputStream(); while ((bytesRead = in.read(buffer, 0, 8192)) != -1) { outs.write(buffer, 0, bytesRead); } outs.flush(); in.close(); rs.close(); } else { rs.close(); } } catch (Exception e) { e.printStackTrace(); } finally { try { pst.close(); m_conn.close(); } catch (SQLException ex) { ex.printStackTrace(); } } 我目前已经连上SQLServer了,img类型的记录也能通过php取出来。只是显示不出。你上述代码执行后没有反映,希望能够给点提示,谢谢。我用的是php,javascript。 header("Content-type: image/jpeg"); mysql VS mysqli,该用哪一个? php时间转换 请教个时间戳字段查询的问题 如何取得字符串的ASCLL码? 同一表中,如何将A字段中所有数据复制到B字段中去 MySQL 4 查询中文问题 谁能提供个动态2级连动下拉菜单代码研究么? 懂PHP且懂点C的大神进来 iwebshop 手机端无法访问pc网站 拆分二维数组组成新的一维数组 关于php邮件问题! 送国际/国内域名+送网页空间+送企业邮局
public ActionForward view(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
PreparedStatement pst = null;
Connection m_conn=null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
m_conn = DriverManager.getConnection(url, "sa", "1234");
String sql = "select pic from picture where id=" + 1;
pst = m_conn.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
if (rs.next()) {
InputStream in = rs.getBinaryStream("pic");//表中图片类型的字段名
int bytesRead = 0;
byte[] buffer = new byte[8192];
//设置照片格式.
response.setContentType("image/gif");
//返回ServletOutputStream 对象.
OutputStream outs = response.getOutputStream();
while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
outs.write(buffer, 0, bytesRead);
}
outs.flush();
in.close();
rs.close();
} else {
rs.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
pst.close();
m_conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}