zoukankan      html  css  js  c++  java
  • jdbc in postgres

    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();
            }
        }
  • 相关阅读:
    ILMerge将源DLL合并到目标EXE
    Nginx+redis的Asp.net
    JwtBearer认证
    Token认证登录以及权限控制
    ES索引
    Linux文本编辑器vim
    集群 安装 配置FastDFS
    When to use next() and return next() in Node.js
    spring-boot-starter-druid
    nodejs express
  • 原文地址:https://www.cnblogs.com/mignet/p/5391136.html
Copyright © 2011-2022 走看看