急....上传文件出错:blob字段,ORA-01465: 无效的十六进制数字
publicvoidfileAdd(AgriFilefile,FormFilefi){con=da.getCon();try{con.setAutoCommit(fals...
public void fileAdd(AgriFile file,FormFile fi) {
con = da.getCon();
try {
con.setAutoCommit(false);
sta = con.createStatement();
sta.executeUpdate("insert into daxing_file values('"
+ file.getFileId() + "','" + file.getFileName()
+ "','"+oracle.sql.BLOB.empty_lob()+"',null,'"
+ file.getPid() + "')");
ResultSet rs = sta.executeQuery("select file_content from daxing_file where file_id='"+file.getFileId()+"' for update");
if (rs.next()) {
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
OutputStream outStream = blob.getBinaryOutputStream();
InputStream in =fi.getInputStream();
byte[] b = new byte[blob.getBufferSize()];
int len = 0;
while ( (len = in.read(b)) != -1) {
outStream.write(b, 0, len);
}
in.close();
outStream.flush();
outStream.close();
con.commit();
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
try {
con.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
} finally {
da.doClose(rs, sta, con);
}
}
我试了下,就是添加blob字段出的错,到底什么问题啊? 展开
con = da.getCon();
try {
con.setAutoCommit(false);
sta = con.createStatement();
sta.executeUpdate("insert into daxing_file values('"
+ file.getFileId() + "','" + file.getFileName()
+ "','"+oracle.sql.BLOB.empty_lob()+"',null,'"
+ file.getPid() + "')");
ResultSet rs = sta.executeQuery("select file_content from daxing_file where file_id='"+file.getFileId()+"' for update");
if (rs.next()) {
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
OutputStream outStream = blob.getBinaryOutputStream();
InputStream in =fi.getInputStream();
byte[] b = new byte[blob.getBufferSize()];
int len = 0;
while ( (len = in.read(b)) != -1) {
outStream.write(b, 0, len);
}
in.close();
outStream.flush();
outStream.close();
con.commit();
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
try {
con.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
} finally {
da.doClose(rs, sta, con);
}
}
我试了下,就是添加blob字段出的错,到底什么问题啊? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询