X

Break New Ground

Configuring the Oracle JDBC drivers with Quarkus

Last but not least on the series of configuring the Oracle JDBC drivers on Java projects we'll have a look at Quarkus, the latest addition to the set of frameworks that let you build applications quickly and with enhanced productivity gains.

Quarkus is a Kubernetes Native Java stack tailored for OpenJDK HotSpot and GraalVM, crafted from the best of breed Java libraries and standards, or said, in other words, a framework that lets you build applications (microservices or else) that can be run in two modes (Java or Native Image) by leveraging the wide range of standards available in the Java space. Quarkus provides these features by exposing a series of extensions that have been carefully crafted to work in both modes.

Getting started with Quarkus is quite easy as shown in this guide, you can either clone an existing repository or use a Maven archetype to bootstrap the project. Lately the preferred way to quickstart a Quarkus project is via https://code.quarkus.io/ as it lets you configure features that you may want to use in your project, such as JDBC, JPA, security, and others. You'll notice that the extension list shows a few options when it comes to database integration but Oracle is missing (as of June 2020). Why is this the case? Remember what I said about Quarkus extensions working in two modes? The Native Image mode from GraalVM imposes some restrictions on the code in order to perform its duties, one of such restriction is limited usage (or none is preferred) of reflection. As of June 2020 the Oracle JDBC drivers have not been fully integrated to GraalVM and for this reason there's no Quarkus extension, yet. The team behind the Oracle JDBC drivers is working on a solution which once released would surely prompt the appearance of a Quarkus extension.

Is there something that can be done in the meantime? Why, yes of course. It's possible to connect Quarkus application to an Oracle database as long as you're running on the Java mode, which is quite fast on its own. Let's say you have created a Quarkus project already, if you're using Apache Maven for building the project then you have to add the following dependencies to your build

In you're building with Gradle instead, then make sure to add these dependencies to your build

Next, browsing the Quarkus guides we find one entitle Configuring your datasources which contains a section on Using a database with no built-in extension or with a different driver. This is exactly what we need. As shown in that guide what we have to do now is add the minimum set of properties to configure the Agroal datasource pool, like so

Finally, the last step is to make use to the configured datasource. Take note that this example uses a named (todos) datasource, thus the persistence dependent code must make a proper named reference like it's shown in the following snippet

And that's all that there is for now regarding the Oracle JDBC drivers and Quarkus. As mentioned earlier, I'd expect better integration between these two technologies once a version of the Oracle JDBC drivers has been refactored to work with GraalVM.

Credits:
Photo by Dimitris Vetsikas

Join the discussion

Comments ( 1 )
  • Larry Peterson Thursday, June 18, 2020
    This worked great once I deleted all the todos references. Thanks,

    Larry
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.