tainos tainos - 5 months ago 203
Java Question

How do I add JDBC drivers and configure JDBC Resources in Payara Micro?

What are my options to set up JDBC drivers and resources when using Java EE Payara Micro?

Answer

Add the datasource definition to your web.xml and then add the jar file for the JDBC jar into your WEB-INF/lib. Then deploy the war file as usual to Payara Micro.

<data-source>
  <name>java:global/ExampleDataSource</name>
  <class-name>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</class-name>
  <server-name>localhost</server-name>
  <port-number>3306</port-number>
  <database-name>mysql</database-name>
  <user>root</user>
  <password>root</password>
  <!-- Example of how to use a Payara specific custom connection pool    setting -->
  <property>
     <name>fish.payara.sql-trace-listeners</name>
     <value>com.sun.gjc.util.SQLTraceLogger</value>
  </property>
</data-source>

There is a complete example of how to do this on the Payara Examples GitHub repository. See Datasource example on Payara GitHub