Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection connection_db(String username, String password, String dbname, Connection c) {
- try {
- Class.forName("org.postgresql.Driver");
- c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/"
- + dbname, username, password);
- System.out.println("Opened database successfully");
- } catch (ClassNotFoundException | SQLException e) {
- System.err.println(e.getClass().getName() + ": " + e.getMessage() + "nnn");
- }
- return c;
- }
- void viewAll(String tableName, long startDate, long endDate, Connection c, String path) {
- String query = "SELECT * FROM " + tableName + " WHERE CAST(receivedtime AS integer) BETWEEN ? AND ? ORDER BY source, receivedtime;";
- try (PreparedStatement stmt = c.prepareStatement(query)) { //try with resources
- stmt.setLong(1, startDate); //prepare query
- stmt.setLong(2, endDate);
- ResultSet rs = stmt.executeQuery();
- try {
- while (rs.next()) { ... }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement