postgres-async-driver
postgres-async-driver copied to clipboard
Provided Example doesn't work
Hi,
i've just started using postgres-async-driver and nothing from provided example worked. here is my code:
`@Bean Db db() { log.info("\n\n==> @ VALUE CONNECTING>> {}/[user:{} , pass: {}]\n", DB_URL, DB_URL,DB_PASS); return new ConnectionPoolBuilder() .hostname("localhost") .port(5432) .database("eve-driver") .username(DB_USER) .password(DB_PASS) .poolSize(20) .build(); } @Autowired private Db db;
public static void main(String[] args) {
SpringApplication.run(DriverApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
db.querySet("select 'Hello world!' as message")
.map(result -> result.row(0).getString("message"))
.subscribe(System.out::println);
System.out.println("----------------------------------");
db.querySet("insert into driver_event(id, type) values($1, $2)", 123, "hello")
.subscribe(result -> System.out.printf("Inserted %d rows", result.updatedRows() ));
}`
but nothing printed at all
As long as you don't have anything waiting for your async code to complete, I suspect your application shuts down before anything has time to run.
@haraldnh
thanks for quick reply. but the application is running not shut down. but no sign that code works even for inserting or retrieve 'hello world'
Hi, as @haraldnh pointed out, you won't get any output if the JVM exits before the queries are completed.
You can also add a second argument to subscribe
to get notified of possible errors (wrong password etc.).
@MuhammedSenussi How did you beat this issue? I am facing the same problem now. Everything had worked just fine, but on last week i found out that query freezes and never ends. Connection is fine, query simply freezes and does nothing. I already tried migration to java 8 from 11, to spring 2.0.3 from 2.1.4. Nothing helped.