Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lib;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Objects;
- import org.postgresql.ds.PGSimpleDataSource;
- public class Databazy {
- public static void main(String[] args) throws SQLException {
- PGSimpleDataSource dataSource = new PGSimpleDataSource();
- dataSource.setServerName("db.dai.fmph.uniba.sk");
- dataSource.setPortNumber(5432);
- dataSource.setDatabaseName("playground");
- dataSource.setUser("mizerik1@uniba.sk");
- dataSource.setPassword("jozko123");
- try(Connection con = dataSource.getConnection()) {
- showEmployees(con, 5, 2);
- }
- }
- public static void showEmployees(Connection con, int pageSize, int pageIndex ) throws SQLException {
- try(Statement s = con.createStatement()) {
- //s.executeQuery("SELECT import_company()");
- String sql = "select employee_id, first_name, last_name from employees";
- sql += " limit " + pageSize;
- try(ResultSet r = s.executeQuery(sql)){
- while(r.next()) {
- int employeeId = r.getInt(1);
- String firstName = r.getString(2);
- String lastName = r.getString(3);
- System.out.println(employeeId + " " + firstName + " " + lastName);
- }
- }
- }
- }
- static boolean compare(Connection c, String sql1, String sql2) throws SQLException {
- try(Statement s1 = c.createStatement()){
- try(Statement s2 = c.createStatement()){
- try(ResultSet r1 = s1.executeQuery(sql1)){
- try(ResultSet r2 = s2.executeQuery(sql2)) {
- ResultMetaData m1 = r1.getMetaData();
- ResultMetaData m2 = r2.getMetaData();
- while(r1.next() && r2.next()) {
- String c1 = r1.getString(1);
- String c2 = r2.getString(1);
- boolean same = Objects.equals(c1, c2);
- if(same == false) {
- return false;
- }
- for(int i=1; i < m1)
- }
- }
- }
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement