以下是读的程序段,供参考
public int getBLOBfromORS(OracleResultSet ors,String outFileName)
{
int CountPerRead = 8192;
byte[] temp = new byte[CountPerRead];
int ret = 0;
try
{
if (ors.next())
{
oracle.sql.BLOB bb = ors.getBLOB(1);
ret = (int)bb.length();
File myFile = new File(outFileName);
myFile.createNewFile();
DataOutputStream myStream = new DataOutputStream(new FileOutputStream(myFile));
int blockCount = ret/CountPerRead;
int blockremain = ret%CountPerRead;
for (int i=0;i<blockCount;i++)
{
temp = bb.getBytes(1+CountPerRead*i,CountPerRead);
myStream.write(temp);
}
temp = bb.getBytes(1+CountPerRead*blockCount,blockremain);
myStream.write(temp,0,blockremain);
myStream.flush();
myStream.close();
}
return ret;
}
catch(Exception e)
{
System.out.println("getBLOBfromORS error!");
return 0;
}
}
>
public int getBLOBfromORS(OracleResultSet ors,String outFileName)
{
int CountPerRead = 8192;
byte[] temp = new byte[CountPerRead];
int ret = 0;
try
{
if (ors.next())
{
oracle.sql.BLOB bb = ors.getBLOB(1);
ret = (int)bb.length();
File myFile = new File(outFileName);
myFile.createNewFile();
DataOutputStream myStream = new DataOutputStream(new FileOutputStream(myFile));
int blockCount = ret/CountPerRead;
int blockremain = ret%CountPerRead;
for (int i=0;i<blockCount;i++)
{
temp = bb.getBytes(1+CountPerRead*i,CountPerRead);
myStream.write(temp);
}
temp = bb.getBytes(1+CountPerRead*blockCount,blockremain);
myStream.write(temp,0,blockremain);
myStream.flush();
myStream.close();
}
return ret;
}
catch(Exception e)
{
System.out.println("getBLOBfromORS error!");
return 0;
}
}
>
PreparedStatement ps;
...
ps.setBinaryStream();
...