// Use dataSource.getConnection() everywhere try (Connection conn = dataSource.getConnection()) // your code
// Store JSON PGobject jsonObj = new PGobject(); jsonObj.setType("json"); jsonObj.setValue("\"key\": \"value\""); pstmt.setObject(1, jsonObj); // Read JSON String jsonStr = rs.getString("data"); postgres jdbc driver
conn.setAutoCommit(false); try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO logs (msg) VALUES (?)")) for (String msg : messages) pstmt.setString(1, msg); pstmt.addBatch(); int[] results = pstmt.executeBatch(); conn.commit(); catch (SQLException e) conn.rollback(); // Use dataSource
// Use dataSource.getConnection() everywhere try (Connection conn = dataSource.getConnection()) // your code
// Store JSON PGobject jsonObj = new PGobject(); jsonObj.setType("json"); jsonObj.setValue("\"key\": \"value\""); pstmt.setObject(1, jsonObj); // Read JSON String jsonStr = rs.getString("data");
conn.setAutoCommit(false); try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO logs (msg) VALUES (?)")) for (String msg : messages) pstmt.setString(1, msg); pstmt.addBatch(); int[] results = pstmt.executeBatch(); conn.commit(); catch (SQLException e) conn.rollback();