码迷,mamicode.com
首页 > 数据库 > 详细

jdbc in postgres

时间:2016-04-14 15:38:24      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

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();
        }
    }

 

jdbc in postgres

标签:

原文地址:http://www.cnblogs.com/mignet/p/5391136.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!