Kohei Nozaki's blog 

Registering PostgreSQL JDBC driver & datasource on WildFly


Posted on Monday Jan 26, 2015 at 07:35AM in Technology


Registering JDBC driver as a module:

module add \
 --name=org.postgresql \
 --resources=/tmp/postgresql-9.3-1102.jdbc41.jar \
 --resource-delimiter=, \
 --dependencies=javax.api,javax.transaction.api

Registering JDBC driver which is referencing a module:

/subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql, \
 driver-module-name=org.postgresql, \
 driver-class-name=org.postgresql.Driver, \
 driver-datasource-class-name=org.postgresql.ds.PGSimpleDataSource, \
 driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)

Registering datasource

data-source add \
 --name=MyDS \
 --driver-name=postgresql \
 --jndi-name=java:jboss/jdbc/MyDS \
 --user-name=wildfly \
 --password=**** \
 --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker \
 --exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter \
 --connection-url=jdbc:postgresql://localhost:5432/wildfly

Registering XA datasource

xa-data-source add \
 --name=MyDS \
 --driver-name=postgresql \
 --jndi-name=java:jboss/jdbc/MyDS \
 --user-name=wildfly \
 --password=****\
 --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker \
 --exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter \
 --xa-datasource-properties={ \
  "ServerName" => "localhost", \
  "PortNumber" => "5432", \
  "DatabaseName" => "wildfly"}

Testing connection:

/subsystem=datasources/xa-data-source=MyDS:test-connection-in-pool

References