我也想知道啊,我读是可以读出来但是显示到页面上有问题javax.servlet.ServletOutputStream op = response.getOutputStream();
ERROR:说我的getOutputStream()已经被我的response调用过了!!

解决方案 »

  1.   

    其实MYSQL和MSSQL的写法一样的,因为都是用SQL,差别只是建立数据库的表吧!不知道对不对!
    问后面的牛人门吧!
      

  2.   

    http://expert.csdn.net/Expert/topic/876/876147.xml?temp=.4891474
      

  3.   

    终于找到了,贡献给大家:JSP+MYSQL存取读取图片
    ----------------------------------------------test.htm
    <HTML> 
    <HEAD> 
    <TITLE>Image File </TITLE> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    </HEAD>
    <body>
    <FORM METHOD="POST" ACTION="testimage.jsp"> 
    <INPUT TYPE="text" NAME="content"><BR> 
    <INPUT TYPE="file" NAME="image"><BR> 
    <INPUT TYPE="submit"></FORM> 
    </body>
    </HTML>
    -------------------------------------testimage.jsp
    <%@ page contentType="text/html;charset=gb2312"%> 
    <%@ page import="java.sql.*" %> 
    <%@ page import="java.util.*"%> 
    <%@ page import="java.text.*"%> 
    <%@ page import="java.io.*"%>
    <%@ include file="getstr.jsp"%>//字符转化,否则不认中文路径
    <%@ include file="inc.jsp"%>//数据库连接的INC文件<%
    String content=request.getParameter("content"); 
    String filename=getStr(request.getParameter("image")); 
    FileInputStream str=new FileInputStream(filename); 
    String sql="insert into picture(content,image) values(?,?)"; //ID号自动增长,所以不用占位
    PreparedStatement pstmt=conn.prepareStatement(sql);
    pstmt.setString(1,content); 
    pstmt.setBinaryStream(2,str,str.available()); 
    pstmt.execute(); 
    out.println("Success,You Have Insert an Image Successfully"); 
    %> 
    -------------------------------------------testimageout.jsp(读取图片)
    <%@ page contentType="text/html;charset=gb2312"%> 
    <%@ page import="java.sql.*" %> 
    <%@ page import="java.util.*"%> 
    <%@ page import="java.text.*"%> 
    <%@ page import="java.io.*"%>
    <%@ include file="inc.jsp"%>
    <html> 
    <body> 
    <%
    String sql = "select image from picture where id=数据库中的图片ID";
    try{ 
    stmt=conn.createStatement(); 
    rs=stmt.executeQuery(sql); 
    }catch(SQLException e){} 
    try { 
    while(rs.next()) {
    response.setContentType("image/gif"); 
    ServletOutputStream sout = response.getOutputStream(); 
    InputStream in = rs.getBinaryStream(1); 
    byte b[] = new byte[0x70120]; 
    for(int i = in.read(b); i != -1;) 

    sout.write(b); 
    in.read(b); 

    sout.flush(); 
    sout.close(); 


    catch(Exception e){System.out.println(e);} 
    %> 
    </body> 
    </html>
      

  4.   

    这在本机做为服务器和客户机时可以成功,但从其它客户机上传图片时不行,
    因为filename是客户机上的路径,服务无法找到这个文件