[jboss-user] [Datasource Configuration] - JBoss AS 7 - Datasource configuration for postgresql

Craig Ringer do-not-reply at jboss.com
Thu May 10 03:15:25 EDT 2012


Craig Ringer [https://community.jboss.org/people/ringerc] commented on the document

"JBoss AS 7 - Datasource configuration for postgresql"

To view all comments on this document, visit: https://community.jboss.org/docs/DOC-17064#comment-9848

--------------------------------------------------
Note that you may instead deploy the PostgreSQL JDBC driver as a module. That's the only way you'll be able to use a -ds.xml file to define a datasource, as far as I can tell anyway.

Create the directory modules/org/postgresql/main and place postgresql-9.1-901-1.jdbc4.jar within it. Now create a module.xml file in the same place, with the content:

<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
   <!-- Load with jboss-cli command:
        /subsystem=datasources/jdbc-driver=postgresql-driver:add(driver-name=postgresql-driver, driver-class-name=org.postgresql.Driver, driver-module-name=org.postgresql)
   -->
   <resources>
     <resource-root path="postgresql-9.1-901-1.jdbc4.jar"/>
   </resources>
   <dependencies>
     <module name="javax.api"/>
     <module name="javax.transaction.api"/>
   </dependencies>
 </module>

Activate it as "postgresql-driver" with 

    jboss-cli.sh --connect command="/subsystem=datasources/jdbc-driver=postgresql-driver:add(driver-name=postgresql-driver, driver-class-name=org.postgresql.Driver, driver-module-name=org.postgresql"

You may now use this driver in -ds.xml files by specifying it as "postgresql-driver", eg:

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
  <datasource jndi-name="java:/datasources/some-ds" enabled="true" use-java-context="true"  
        pool-name="some-ds-pool">
    <connection-url>jdbc:postgresql:somedb</connection-url>
    <driver>postgresql-driver</driver>
    <security>
      <user-name>user</user-name>
      <password>pass</password>
    </security>
  </datasource>
</datasources>



Unlike explicitly naming the jdbc jar in a data-source create command, you can now update PgJDBC without changing all your datasources.
--------------------------------------------------

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120510/6f2c74c6/attachment-0001.html 


More information about the jboss-user mailing list