http://www.csdn.net/expert/topic/557/557668.xml?temp=.8389246
这是JSP版上的一片相关的文章

解决方案 »

  1.   

    别人的东西:
     Object source = e.getSource();
        try
        {
          if (conn.isClosed())
            conn = DriverManager.getConnection("jdbc:weblogic:mssqlserver4", props);
        }
        catch ( Exception ex )
        {
          ex.printStackTrace();
        }    if ( source == App.frame.jButton1 )
        {
          String StrSql = "insert into ServletDB values (?,?,?,?)";      try
          {
            File f = new File("c:\\1.png");
            FileInputStream fin = new FileInputStream(f);        PreparedStatement ps = conn.prepareStatement(StrSql);
            ps.setString(1,"李丽华");
            ps.setInt(2,12);
            ps.setString(3,"RD");
            int len = (int)f.length();
            ps.setBinaryStream(4,fin,len);        ps.executeUpdate();        ps.close();        fin.close();      }
          catch ( Exception ex )
          {
            ex.printStackTrace();
          }
        }
        else
        {
          try
          {
            FileOutputStream fou = new FileOutputStream("c:\\2.png");        Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery("Select * from ServletDB where UserPassWord = 12 ");        while (rs.next())
            {
              InputStream imagedata = rs.getBinaryStream("image");          byte[] idata = new byte[8000];
              int rec = imagedata.read(idata);
              fou.write(idata);
              idata = null;        }        st.close();
            rs.close();
            fou.close();
          }
          catch (Exception ex )
          {
            ex.printStackTrace();
          }
        }    try
        {
          conn.close();
        }
        catch ( Exception ex )
        {
          ex.printStackTrace();
        }
      }
      

  2.   

    下载一个oracle.xml.sql.query.OracleXMLQuery包,里面可以有getXMLString()方法,通过它可以直接把图片的16进制原封不动的转换成XML中的字符串,在插入数据库的时候,将该字符串前面加上0x,不加引号,写入SQL语句中,通过调用oracle.jdbc.driver包,就可以存入数据库!