标签:
try { Class.forName("org.postgresql.Driver").newInstance(); String url = "jdbc:postgresql://localhost:5432/erp"; String user = "xx"; String pwd = "xx"; Connection conn = DriverManager.getConnection(url, user, pwd); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM goods_picture where md5 is null"); List<String> paths = new ArrayList<String>(); int i = 0; while (rs.next()) { i++; LOGGER.debug(rs.getString(1));//id LOGGER.debug(rs.getString(2));//goodsid LOGGER.debug(rs.getString(3));//seqno LOGGER.debug(rs.getString(4));//picturetypeid LOGGER.debug(rs.getString(5));//title LOGGER.debug(rs.getString(6));//path paths.add(rs.getString(6)); LOGGER.debug(rs.getString(7));//companyid LOGGER.debug(rs.getString(8)); LOGGER.debug(rs.getString(9)); LOGGER.debug(rs.getString(10)); } LOGGER.debug("total:"+i); rs.close(); st.close(); //批量更新 conn.setAutoCommit(false); Statement stmt =conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); for(int x = 0; x < paths.size();x++){ String path = paths.get(x); String md5 = ImageMigrator.readAndUpload(null,path); if(md5!=null){ stmt.addBatch("update goods_picture set md5=‘"+md5+"‘ where path=‘"+path+"‘"); } } stmt.executeBatch(); conn.commit(); stmt.close(); conn.close(); } catch (Exception e) { e.printStackTrace(); } }
标签:
原文地址:http://www.cnblogs.com/mignet/p/5391136.html