当前位置: 技术问答>java相关
BLOB很奇怪的问题,高分相送!
来源: 互联网 发布时间:2017-04-09
本文导语: ... import oracle.sql.*; public Vector findBlobMany(Object bean,String where){ Vector vRet = new Vector(); String tableName = getProperty(bean,"table_name"); String primaryKey = getProperty(bean,"primary_key"); String columnList = getPr...
...
import oracle.sql.*;
public Vector findBlobMany(Object bean,String where){
Vector vRet = new Vector();
String tableName = getProperty(bean,"table_name");
String primaryKey = getProperty(bean,"primary_key");
String columnList = getProperty(bean,"column_list");;
String[] cNames = StringUtil.toArray(columnList);
String blobName = cNames[0];
String sql = "select "+columnList+" from "+tableName;
if(where!=null&&where.length()>1) sql +=" where "+where;
show(sql);
Connection conn = null;
InputStream is;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = getConnection();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery(sql);
BLOB blob ;
while(rs.next()){
Class c = bean.getClass();
Class.forName(c.getName());
bean = c.newInstance();
blob = ((oracle.jdbc.OracleResultSet)rs).getBLOB(1);//读出第一个BLOB字段
///////////////////////////////////////
try{
OutputStream fout = blob.getBinaryOutputStream();
File file = new File("d:\out.txt");
InputStream fin = new FileInputStream(file);
byte[] buffer = new byte[blob.getBufferSize()];
fin.read(buffer);
System.out.println(buffer);
fout.write(buffer);
int bytesRead = 0;
while((bytesRead = fin.read(buffer)) != -1)
{
fout.write(buffer, 0, bytesRead);
System.out.println(bytesRead);
}
}catch(Exception ex){
ex.printStackTrace();
}
//////////////////////////////////////
for(int i=1;i
import oracle.sql.*;
public Vector findBlobMany(Object bean,String where){
Vector vRet = new Vector();
String tableName = getProperty(bean,"table_name");
String primaryKey = getProperty(bean,"primary_key");
String columnList = getProperty(bean,"column_list");;
String[] cNames = StringUtil.toArray(columnList);
String blobName = cNames[0];
String sql = "select "+columnList+" from "+tableName;
if(where!=null&&where.length()>1) sql +=" where "+where;
show(sql);
Connection conn = null;
InputStream is;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = getConnection();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery(sql);
BLOB blob ;
while(rs.next()){
Class c = bean.getClass();
Class.forName(c.getName());
bean = c.newInstance();
blob = ((oracle.jdbc.OracleResultSet)rs).getBLOB(1);//读出第一个BLOB字段
///////////////////////////////////////
try{
OutputStream fout = blob.getBinaryOutputStream();
File file = new File("d:\out.txt");
InputStream fin = new FileInputStream(file);
byte[] buffer = new byte[blob.getBufferSize()];
fin.read(buffer);
System.out.println(buffer);
fout.write(buffer);
int bytesRead = 0;
while((bytesRead = fin.read(buffer)) != -1)
{
fout.write(buffer, 0, bytesRead);
System.out.println(bytesRead);
}
}catch(Exception ex){
ex.printStackTrace();
}
//////////////////////////////////////
for(int i=1;i