首先把文件读到一个FileInputStream in中然后直接调用ps.setBinaryStream(1,in,(int)fileSize);fileSize是文件的长度!

解决方案 »

  1.   

    可是我怎么读呢,这个上传程序写文件时候是从字节数组里取出来的数据如下
    File f=new File(uploadpath+filename);
    DataOutputStream fileout=new DataOutputStream(new FileOutputStream(f));


    //字节数组再往下一行,4表示两个回车换行占4个字节,本行的回车换行2个字节,Content-type的下一行是回车换行表示的空行,占2个字节
    //得到文件数据的起始位置
    b=subBytes(b,s.getBytes().length+4,b.length);
    pos=byteIndexOf(b,boundary,0);//定位文件数据的结尾
    b=subBytes(b,0,pos-1);//取得文件数据
    //fin.write(b,0,b.length-1);
    fileout.write(b,0,b.length-1);
    我怎么才能去出FileInputStream?谢谢你了,请你帮忙给解决一下,我实在是不懂了!
      

  2.   

    好办。已经测试成功。
    ByteArrayInputStream fou1 = new ByteArrayInputStream(idata);
    ps = conn.prepareStatement(StrSql);
    int len = idata.length;
    ps.setBinaryStream(6,fou1 ,len);
      

  3.   

    idata是接收到的图像数据。当然是个byte[] idata = new byte[8000]
      

  4.   

    你测试成功了吗?我象下面这样做怎么还是不能插入到数据库中啊?你在帮帮吧
    ByteArrayInputStream fou1 = new ByteArrayInputStream(b);
    rc=update(fou1,fileSize,filename);
      

  5.   

    你可以把测试成功的代码给我看看吗,我现在总提示null错误,我被弄的昏到涨脑的,我的qq是25809355,能在QQ上聊聊吗?
      

  6.   

    这样吧,你先在client端把图像显示出来。如果显示正确,那就说明你传出来的数据是正确的,没有是空值。
    确定图像数据正确后再往后走。成功添加上了:
    fin = new FileInputStream(f);
    ////////////////////////////////////////
    byte[] ib = new byte[(int)f.length()];
    fin.read(ib);
    ByteArrayInputStream fou1 = new ByteArrayInputStream(ib);
    ps = conn.prepareStatement(StrSql); ps.setInt(1,intCurrent+1);
    ps.setString(2,sFile);
    ps.setString(3,sFile.substring(sFile.length()-3));
    ps.setString(4,f.getPath());
    ps.setInt(5,(int)f.length());
    //ps.setDate(6,null,null);
    int len = (int)f.length();
    ps.setBinaryStream(6,fou1,len);
    ps.executeUpdate();
    ps.clearParameters();
    ps.close();
    ps = null;
      

  7.   

    这样吧,你先在client端把图像显示出来。如果显示正确,那就说明你传出来的数据是正确的,没有是空值。
    确定图像数据正确后再往后走。成功添加上了:
    fin = new FileInputStream(f);
    ////////////////////////////////////////
    byte[] ib = new byte[(int)f.length()];
    fin.read(ib);
    ByteArrayInputStream fou1 = new ByteArrayInputStream(ib);
    ps = conn.prepareStatement(StrSql); ps.setInt(1,intCurrent+1);
    ps.setString(2,sFile);
    ps.setString(3,sFile.substring(sFile.length()-3));
    ps.setString(4,f.getPath());
    ps.setInt(5,(int)f.length());
    //ps.setDate(6,null,null);
    int len = (int)f.length();
    ps.setBinaryStream(6,fou1,len);
    ps.executeUpdate();
    ps.clearParameters();
    ps.close();
    ps = null;