//参数意义:SQL语句,生成的文件名,字段名称,下面的方法将生成为FileName指定的文件,你参考一下吧
public void WriteToFileByOdbc(String sql,String FileName,String Zd){
    countInt=0;
    try{
      drpRst = drpStmt.executeQuery(sql);
      if (drpRst.next()){
         InputStream ins=drpRst.getBinaryStream(Zd);
         FileOutputStream fos=new FileOutputStream(FileName);
        int readbyte=0;
        while (true)
         {
           readbyte=ins.read();
          if (readbyte==-1)
               break;
           fos.write(readbyte);
         }
          ins.close();
          }
        countInt=1;//写入成功
        }catch(FileNotFoundException aa){
          countInt=-1;
          System.out.println("File error");
        }catch(SQLException sqly){
          countInt=-1;
          System.out.println("Sql error");
        }catch(IOException io){
          countInt=-1;
          System.out.println("IO error");
        }
   }