//参数意义: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");
}
}
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");
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货