问:如何将文件存在数据库中,怎么存储,读取? 在數據庫表中定義一個類型為CLOB 的列﹐即可以把文本文件放進來。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /* 名称:saveFileToBlob 功能:把图形文件保存到oracle数据库 输入参数:无 输出参数: 0 成功 1 失败 */ public int saveFileToBlob(String sDirName,String sCaseNo,String sPerson) { File[] file = new File(sDirName).listFiles(); String sFileName=""; for(int i=0;i<file.length;i++) { if(file[i].isFile() && file[i].getName().indexOf("jpg")!=-1 ) { sFileName = file[i].getName(); try { FileInputStream FileInput= new FileInputStream(sDirName + "\\"+sFileName); m_connection.setAutoCommit(false); Statement stmt = m_connection.createStatement(); CallableStatement callStmt = m_connection.prepareCall("call getrowId(?,?)"); //取row_id callStmt.registerOutParameter(2, Types.VARCHAR); callStmt.setString(1, "image"); callStmt.execute(); String strRowId = callStmt.getString(2); String strSqlInsertBlob = "insert into image ....)"; stmt.execute(strSqlInsertBlob); ResultSet rts = stmt.executeQuery("select image from image ......"); BLOB blob = null; if(rts.next()!=false) { blob = ( (OracleResultSet) rts).getBLOB(1); OutputStream out = blob.getBinaryOutputStream(blob.length()); int chunk = blob.getChunkSize(); byte[] buffer = new byte[chunk]; int flength = -1; while ( (flength = FileInput.read(buffer)) != -1) out.write(buffer, 0, flength); out.close(); FileInput.close(); m_connection.commit(); rts.close(); stmt.close(); callStmt.close(); } else { FileInput.close(); rts.close(); stmt.close(); callStmt.close(); } } catch(Exception e) { System.out.println(e.toString()); System.out.println(e.getClass().toString()); return 1; } } } deleteFile(sDirName); if (m_connection!=null) try { m_connection.close(); } catch (Exception e) {} return 0; } BLOB OracleResultSet都是什么包里的啊? 怎么能insert update delete, bolb类型的字段???help! oracle User/IO很高问题??? 建物化视图的时候报权限不足 根据传入的时间得到最近30天的时间 请教一条select语句的写法! pl sql存储过程中如何捕获数据被锁定 求:在游标中如何使用可能为空的参数? 帮忙看看!!!谢谢!!! 不使用包,仅使用过程,能否返回结果集? 各路英雄挺身而出,出手相救!(500分) oracle 中 用什么 替换 mysql中 regexp 表达式 菜鸟写触发器和存储过程的问题,急,在线等!!! 名词解释:RDMS SGA PGA MONT DBWR LGWR
名称:saveFileToBlob
功能:把图形文件保存到oracle数据库
输入参数:无
输出参数: 0 成功 1 失败
*/
public int saveFileToBlob(String sDirName,String sCaseNo,String sPerson)
{
File[] file = new File(sDirName).listFiles();
String sFileName="";
for(int i=0;i<file.length;i++)
{ if(file[i].isFile() && file[i].getName().indexOf("jpg")!=-1 )
{ sFileName = file[i].getName();
try
{
FileInputStream FileInput= new FileInputStream(sDirName + "\\"+sFileName);
m_connection.setAutoCommit(false);
Statement stmt = m_connection.createStatement();
CallableStatement callStmt = m_connection.prepareCall("call getrowId(?,?)");
//取row_id
callStmt.registerOutParameter(2, Types.VARCHAR);
callStmt.setString(1, "image");
callStmt.execute();
String strRowId = callStmt.getString(2);
String strSqlInsertBlob = "insert into image ....)";
stmt.execute(strSqlInsertBlob);
ResultSet rts = stmt.executeQuery("select image from image ......");
BLOB blob = null;
if(rts.next()!=false)
{
blob = ( (OracleResultSet) rts).getBLOB(1);
OutputStream out = blob.getBinaryOutputStream(blob.length());
int chunk = blob.getChunkSize();
byte[] buffer = new byte[chunk];
int flength = -1;
while ( (flength = FileInput.read(buffer)) != -1)
out.write(buffer, 0, flength);
out.close();
FileInput.close();
m_connection.commit();
rts.close();
stmt.close();
callStmt.close(); }
else {
FileInput.close();
rts.close();
stmt.close();
callStmt.close();
}
}
catch(Exception e)
{
System.out.println(e.toString());
System.out.println(e.getClass().toString());
return 1;
} }
}
deleteFile(sDirName);
if (m_connection!=null)
try
{
m_connection.close();
}
catch (Exception e) {}
return 0; }