日期:2014-05-16 浏览次数:20579 次
private static void Removetodata2(String path) { Session session = null; Connection conn = null; java.sql.Statement stmt = null; try { session = SessionFactory.openSession(EasySQL.ORACLE, "jdbc:oracle:thin:@127.0.0.1:1521:oradb", "data", "data", false, EasySQL.ORACLE_DRIVER); conn = session.getConnection(); conn = session.getConnection(); boolean defaultCommit = conn.getAutoCommit(); //关闭自动提交 conn.setAutoCommit(false); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); String str = "FileName State"; //日志头 File file = new File(new Date().getTime() + ".txt"); //插入日志 FileInputStream fis = null; File folderfiles = new File(path);//文件夹路径 BufferedOutputStream out = null; BufferedInputStream in = null; File[] files = folderfiles.listFiles(); //获取所有文件 for (int i = 0; i < files.length; i++) {//第一层目录 File sonfiles = files[i]; //获取子文件夹中的子文件 str += "\r\n"; str += "==========================================" + files[i].getName() + ":文件夹:start=================================================="; count = count + 1; System.out.println(count + "-开始:=============" + sonfiles.getName()); if (sonfiles.length() < 2 * 1024 * 1024) { //小于2M的文件上传 /** * 之所以用like 是因为路径问题. file_manage 里面的file_name 里有 * “区划/文件名” 所以like 一下就不用考虑"/"的问题.直接把子文件夹里得的数据拿出来 */ ResultSet rs = stmt .executeQuery("select bzgl.file_manage.file_remark2 as qhdm ,data.taizhang.wh as tzwh,bzgl.file_manage.file_wenhao as wenhao,bzgl.file_manage.file_name as filename,data.taizhang.smwjmc as smwjmc,data.taizhang.smwjlx as smwjlx,data.taizhang.smwj as smwj from bzgl.file_manage right join data.taizhang on bzgl.file_manage.file_wenhao= data.taizhang.wh where bzgl.file_manage.file_name like'%" + sonfiles.getName() + "%' for update");//锁定选择文件 while (rs.next()) { fis = new FileInputStream(sonfiles); accesscount = accesscount + 1; //成功插入个数 String filename = rs.getString("filename"); String wh = rs.getString("tzwh"); //更新该文号下面的台账 扫描文件名称和类型. Query query = session.createQuery("update taizhang set smwjmc='" + filename.substring(0, filename.indexOf(".")) + "',smwjlx='" + filename.substring(filename.indexOf(".") + 1, filename.length()) + "' where wh='" + wh + "'"); query.executeUpdate();//循环记录 记录一次 if(rs.isLast()){ System.out.println(filename + ":更新完毕"); str += "\r\n"; str +="文号:【"+wh+"】 文件名:【"+ filename + "】 [Access] "; } //日志文件记录 oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("smwj"); //批量修改 out = new BufferedOutputStream(blob.getBinaryOutputStream());