3

Is it possible to open a database connection at runtime using quarkus jdbc drivers? If so how would I go about doing it. Also would the mechanism work with native images?

Basically I wish to get a connection object to the database so I can run a custom query.

user3690467
  • 3,049
  • 6
  • 27
  • 54

2 Answers2

0

You can override some properties at runtime. You can view them here:

quarkus datasources

Luisao
  • 455
  • 2
  • 9
  • 20
0

runtime sounds confusing. You can override BEFORE starting app. Imagine the case, you have url_XXX and url_YYY. You can start app with

-Dquarkus.datasource.jdbc.url=url_XXX

and get datasource with connection to url_XXX. There is no option to get connection to url_YYY in runtime. You'll have to restart app with

-Dquarkus.datasource.jdbc.url=url_YYY

in order to connect to different DB.

Another option would be to use named datasources, but still you have define them at build time and provide url BEFORE starting app.

-Dquarkus.datasource.YYY.jdbc.url=url_YYY -Dquarkus.datasource.XXX.jdbc.url=url_XXX

Quarkus names it "runtime", but actually it's "pre-runtime"

Capacytron
  • 3,425
  • 6
  • 47
  • 80