我是要通过JSP把图片保存在数据库的一个字段中。 并且可以提出来显示在网页上。不想保存图片的路径。数据库是ORACLE数据库。请问谁知道怎么做?

解决方案 »

  1.   

    写入: 
      out  =  response.getWriter(); 
    Connection  conn  =  DriverManager.getConnection("",  "",  ""); 
    //INSERT  A    FILE  INTO  THE  DATABASE! 
    File  file  =  new  File("D:\\d.bmp"); 
    FileInputStream  fis  =  new  FileInputStream(file); 
    String  strsql  ="INSERT  INTO  tp(tp,dm)  VALUES  (?,'01')"; 
    PreparedStatement  ps  =  conn.prepareStatement(strsql); 
    ps.setBinaryStream(1,  fis,  (int)(file.length())); 
    ps.executeUpdate(); 
    out.println("INSERT  FILE  OK:::::"); 
    ps.close(); 
    fis.close(); 
    读出: 
    PreparedStatement  pres  =  conn.prepareStatement("SELECT  tp  FROM  tp  WHERE  dm='01'"); 
    ResultSet  res  =  pres.executeQuery(); 
    if  (res  !=  null)  

    while(res.next())  

                  InputStream  is  =  res.getBinaryStream(1); 
          //  use  the  stream  in  some  way  here 
    OutputStream  outstr  =  new  BufferedOutputStream(  new  FileOutputStream("d:\\new.bmp")); 
    //  Read    the  URL  and  write  it  to  a  file 
    byte  bufferb[]  =  new  byte[64]; 
    //  Buffer  to  store      lines 
    int  nread; 
    while(0<=(nread  =  is.read(bufferb))) 
              outstr.write(bufferb,  0,  nread); 
                  is.close(); 
                  outstr.close();      

    res.close(); 

    pres.close(); 
    这样图片放在服务器:d:\new.bmp
      

  2.   

    TO:WZ7652(小王)大家来评评理啊 , 我不会就问,这个人怎么能说我笨呢?
      

  3.   

    TO:zhangyonggang(沙沙) 我是想把图片的数据存在数据库里而不是存在服务器的目录里。你有办法吗?
      

  4.   

    http://www.csdn.net/expert/topic/762/762687.xml?temp=.7781183
      

  5.   

    给个具体例子,用数据流读书据
    chat* thanks
      

  6.   

    InputStream    is    =    res.getBinaryStream(1);
    (1)中的1是什么含义?
    我为什么执行后is是null值?
    请各位大虾帮忙!!!!!!!!