Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. package lib;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.util.Objects;
  8.  
  9. import org.postgresql.ds.PGSimpleDataSource;
  10.  
  11. public class Databazy {
  12.  
  13.  
  14. public static void main(String[] args) throws SQLException {
  15. PGSimpleDataSource dataSource = new PGSimpleDataSource();
  16. dataSource.setServerName("db.dai.fmph.uniba.sk");
  17. dataSource.setPortNumber(5432);
  18. dataSource.setDatabaseName("playground");
  19. dataSource.setUser("mizerik1@uniba.sk");
  20. dataSource.setPassword("jozko123");
  21. try(Connection con = dataSource.getConnection()) {
  22. showEmployees(con, 5, 2);
  23. }
  24. }
  25.  
  26. public static void showEmployees(Connection con, int pageSize, int pageIndex ) throws SQLException {
  27. try(Statement s = con.createStatement()) {
  28. //s.executeQuery("SELECT import_company()");
  29. String sql = "select employee_id, first_name, last_name from employees";
  30. sql += " limit " + pageSize;
  31. try(ResultSet r = s.executeQuery(sql)){
  32. while(r.next()) {
  33. int employeeId = r.getInt(1);
  34. String firstName = r.getString(2);
  35. String lastName = r.getString(3);
  36. System.out.println(employeeId + " " + firstName + " " + lastName);
  37. }
  38. }
  39. }
  40. }
  41.  
  42. static boolean compare(Connection c, String sql1, String sql2) throws SQLException {
  43. try(Statement s1 = c.createStatement()){
  44. try(Statement s2 = c.createStatement()){
  45. try(ResultSet r1 = s1.executeQuery(sql1)){
  46. try(ResultSet r2 = s2.executeQuery(sql2)) {
  47. ResultMetaData m1 = r1.getMetaData();
  48. ResultMetaData m2 = r2.getMetaData();
  49.  
  50.  
  51. while(r1.next() && r2.next()) {
  52. String c1 = r1.getString(1);
  53. String c2 = r2.getString(1);
  54. boolean same = Objects.equals(c1, c2);
  55. if(same == false) {
  56. return false;
  57. }
  58. for(int i=1; i < m1)
  59. }
  60. }
  61. }
  62. }
  63. }
  64. return true;
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement