Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. Connection connection_db(String username, String password, String dbname, Connection c) {
  2. try {
  3. Class.forName("org.postgresql.Driver");
  4. c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/"
  5. + dbname, username, password);
  6. System.out.println("Opened database successfully");
  7. } catch (ClassNotFoundException | SQLException e) {
  8. System.err.println(e.getClass().getName() + ": " + e.getMessage() + "nnn");
  9. }
  10. return c;
  11. }
  12.  
  13. void viewAll(String tableName, long startDate, long endDate, Connection c, String path) {
  14. String query = "SELECT * FROM " + tableName + " WHERE CAST(receivedtime AS integer) BETWEEN ? AND ? ORDER BY source, receivedtime;";
  15.  
  16. try (PreparedStatement stmt = c.prepareStatement(query)) { //try with resources
  17. stmt.setLong(1, startDate); //prepare query
  18. stmt.setLong(2, endDate);
  19. ResultSet rs = stmt.executeQuery();
  20.  
  21. try {
  22. while (rs.next()) { ... }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement