Guest User

Untitled

a guest
Apr 28th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package main.com.safenetpay.thirdproject;
  2.  
  3. import io.vertx.core.Vertx;
  4. import io.vertx.pgclient.PgConnectOptions;
  5. import io.vertx.pgclient.PgPool;
  6. import io.vertx.sqlclient.PoolOptions;
  7.  
  8. public class PersonDao {
  9.  
  10.     PgConnectOptions connectOptions;
  11.     PoolOptions poolOptions;
  12.     PgPool client;
  13.  
  14.     public PersonDao(Vertx vertx) {
  15.         connectOptions = new PgConnectOptions().setPort(5432).setHost("localhost").setDatabase("db").setUser("postgres")
  16.                 .setPassword("postgres");
  17.         poolOptions = new PoolOptions().setMaxSize(5);
  18.         client = PgPool.pool(vertx, connectOptions, poolOptions);
  19.     }
  20.  
  21.     public void getPersons() {
  22.         client.query("SELECT * FROM db").execute(res->{
  23.             try {
  24.                 if (res.succeeded()) {
  25.                     System.out.println(res.result());
  26.                 } else {
  27.               System.out.println("Failure: " + res.cause().getMessage());    
  28.                 }
  29.             } catch (Exception e) {
  30.                 System.out.println(e);
  31.             }  
  32.         });
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment