Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HikariDataSource ds = new HikariDataSource();
- ds.setJdbcUrl("jdbc:postgresql://localhost/test");
- ds.setUsername("postgres");
- ds.setPassword("postgres");
- Connection connection = ds.getConnection();
- connection.setReadOnly(true);
- connection.setAutoCommit(false);
- Statement statement = connection.createStatement();
- statement.setFetchSize(100);
- ResultSet resultSet = statement.executeQuery("SELECT gid, (ST_Dump(geom)).geom FROM distrikt_v1_b");
- Connection connection3 = ds.getConnection();
- Connection connection2 = null;
- PreparedStatement add = null;
- PreparedStatement error = null;
- int count = 0;
- while (resultSet.next()) {
- System.out.println("Processing row " + count);
- if (count % 1000 == 0) {
- if (connection2 != null) {
- connection2.close();
- }
- connection2 = ds.getConnection();
- connection3.createStatement().execute("VACUUM ANALYZE topo.edge_data");
- connection3.createStatement().execute("VACUUM ANALYZE topo.face");
- connection3.createStatement().execute("VACUUM ANALYZE topo.node");
- add = connection2.prepareStatement("SELECT TopoGeo_AddLineString('topo', ?, 1)");
- error = connection2.prepareStatement("INSERT INTO errors VALUES (?, ?)");
- }
- Object geom = resultSet.getObject("geom");
- add.setObject(1, geom);
- try {
- add.execute();
- } catch (PSQLException e) {
- error.setInt(1, resultSet.getInt("gid"));
- error.setString(2, e.getMessage());
- error.executeUpdate();
- }
- count++;
- }
- resultSet.close();
- statement.close();
- connection.close();
- connection3.close();
- ds.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement