1

im new in Microprofile world and im trying to create a microservices using Open Liberty as implementation. The main problem here starts when im trying to connect to my database using MySql, and i cant find the reason. My server.xml file is the next one:

<library id="jdbcLib">
    <fileset dir="jdbc" includes="*.jar"/>
</library>

<dataSource jndiName="jdbc/myDB">
    <jdbcDriver libraryRef="jdbcLib"/>
    <properties serverName="localhost" portNumber="3306"
                databaseName="inventory"
                user="root"
                password="root"/>
</dataSource>

And my persistence.xml file is:

<persistence-unit name="jpa-unit" transaction-type="JTA">
    <jta-data-source>jdbc/myDB</jta-data-source>
    <properties>
        <property name="eclipselink.ddl-generation" value="create-tables"/>
        <property name="eclipselink.ddl-generation.output-mode" value="both" />
    </properties>
</persistence-unit>

I cant find what im doing wrong, but im getting the following exception:

java.sql.SQLNonTransientException: DSRA4000E: No implementations of [javax.sql.ConnectionPoolDataSource, javax.sql.DataSource, javax.sql.XADataSource, java.sql.Driver] are found for dataSource[default-0] with library jdbcLib

Someone could help me out with this? i would be very grateful :D

Rodrigo
  • 13
  • 2
  • Open Liberty doesn't come pre-packaged with JDBC driver binaries. From your server.xml your configuration of the JDBC driver looks good but you still need to take the step of copying it into place on disk. The answer by @marks is a good approach, using Maven. – Scott Kurz Aug 10 '21 at 13:31
  • 1
    Yes Scott, thanks u very much for the reply, mark's answer works great for me – Rodrigo Aug 11 '21 at 12:41
  • That's great to hear. In that case you can go ahead and accept the answer. Glad to help. – Scott Kurz Aug 11 '21 at 12:52

1 Answers1

1

It looks like you followed the example here: https://openliberty.io/docs/21.0.0.3/relational-database-connections-JDBC.html

Based on the exception, it looks like the driver jar isn't in the jdbc directory (which will be wlp/usr/server/server_name/jdbc) You should be able to get the version you need here: https://mvnrepository.com/artifact/mysql/mysql-connector-java

If you're using maven, you can use the Liberty Maven Plugin to download and copy the driver to the correct directory for you. Here's an example using the latest 8.0.26 driver:

<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.3</version>
  <configuration>
    <copyDependencies>
        <location>jdbc</location>
        <dependency> 
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <!-- You can omit the version below if you have 
                 declared a dependency and want to simply use 
                 that version, or specify the version as shown 
                 if you don't include this artifact as a dependency. -->
            <version>8.0.26</version> 
        </dependency>
    </copyDependencies>
  </configuration>
</plugin>
Scott Kurz
  • 4,985
  • 1
  • 18
  • 40
mswatosh
  • 466
  • 2
  • 8
  • 1
    The answer was good but it followed the pattern used in an early, milestone release. I updated the answer to reflect the support in its final, release format. – Scott Kurz Aug 10 '21 at 13:25
  • @ScottKurz Thanks for the update, I tried that out and it works. I see there was actually an issue opened yesterday to fix this specific example: https://github.com/OpenLiberty/docs/issues/4517 – mswatosh Aug 10 '21 at 14:00
  • Ah, thanks too for the pointer. Looks like we're fixing that other doc. – Scott Kurz Aug 10 '21 at 14:09
  • Thanks you very much guys, this works great in my project, i'm very grateful! – Rodrigo Aug 11 '21 at 12:42