Advertisement
Guest User

Untitled

a guest
Oct 13th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. HikariDataSource ds = new HikariDataSource();
  2. ds.setJdbcUrl("jdbc:postgresql://localhost/test");
  3. ds.setUsername("postgres");
  4. ds.setPassword("postgres");
  5.  
  6. Connection connection = ds.getConnection();
  7. connection.setReadOnly(true);
  8. connection.setAutoCommit(false);
  9. Statement statement = connection.createStatement();
  10. statement.setFetchSize(100);
  11. ResultSet resultSet = statement.executeQuery("SELECT gid, (ST_Dump(geom)).geom FROM distrikt_v1_b");
  12.  
  13. Connection connection3 = ds.getConnection();
  14.  
  15. Connection connection2 = null;
  16. PreparedStatement add = null;
  17. PreparedStatement error = null;
  18.  
  19. int count = 0;
  20. while (resultSet.next()) {
  21. System.out.println("Processing row " + count);
  22.  
  23. if (count % 1000 == 0) {
  24. if (connection2 != null) {
  25. connection2.close();
  26. }
  27. connection2 = ds.getConnection();
  28. connection3.createStatement().execute("VACUUM ANALYZE topo.edge_data");
  29. connection3.createStatement().execute("VACUUM ANALYZE topo.face");
  30. connection3.createStatement().execute("VACUUM ANALYZE topo.node");
  31. add = connection2.prepareStatement("SELECT TopoGeo_AddLineString('topo', ?, 1)");
  32. error = connection2.prepareStatement("INSERT INTO errors VALUES (?, ?)");
  33. }
  34.  
  35. Object geom = resultSet.getObject("geom");
  36. add.setObject(1, geom);
  37. try {
  38. add.execute();
  39. } catch (PSQLException e) {
  40. error.setInt(1, resultSet.getInt("gid"));
  41. error.setString(2, e.getMessage());
  42. error.executeUpdate();
  43. }
  44.  
  45. count++;
  46. }
  47. resultSet.close();
  48. statement.close();
  49. connection.close();
  50. connection3.close();
  51. ds.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement