postgres-async-driver icon indicating copy to clipboard operation
postgres-async-driver copied to clipboard

Provided Example doesn't work

Open MuhammedSenussi opened this issue 8 years ago • 4 comments

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

MuhammedSenussi avatar Nov 20 '16 17:11 MuhammedSenussi

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 avatar Nov 20 '16 19:11 haraldnh

@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'

MuhammedSenussi avatar Nov 21 '16 09:11 MuhammedSenussi

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.).

alaisi avatar Nov 21 '16 19:11 alaisi

@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.

anko94 avatar Jun 17 '19 11:06 anko94