Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we configure database connection from JBOSS?

Can we configure database connection from JBOSS? If it is possible, than is there any configuration file in JBOSS to configure database connection from JBOSS?

like image 701
kandarp Avatar asked Dec 16 '10 09:12

kandarp


1 Answers

You need two things:

  1. Make the JDBC driver available to your Applications Server
  2. Write a Data Source configuration

For #1, you can download the JAR containing JDBC driver and put it in the following directory:

$JBOSS_HOME/server/default/lib

Assuming that $JBOSS_HOME points to your JBoss installation, and you are using default installation.

For #2, you will find a lot of examples here:

$JBOSS_HOME/docs/examples/jca

There are examples for most of database products around. Here's PostgreSQL's:

<datasources>
  <local-tx-datasource>
    <jndi-name>PostgresDS</jndi-name>
    <connection-url>jdbc:postgresql://[servername]:[port]/[database name]</connection-url>
    <driver-class>org.postgresql.Driver</driver-class>
    <user-name>x</user-name>
    <password>y</password>
        <!-- sql to call when connection is created.  Can be anything, select 1 is valid for PostgreSQL
        <new-connection-sql>select 1</new-connection-sql>
        -->

        <!-- sql to call on an existing pooled connection when it is obtained from pool.  Can be anything, select 1 is valid for PostgreSQL
        <check-valid-connection-sql>select 1</check-valid-connection-sql>
        -->

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
      <metadata>
         <type-mapping>PostgreSQL 7.2</type-mapping>
      </metadata>
  </local-tx-datasource>

</datasources>
like image 122
Pablo Santa Cruz Avatar answered Oct 03 '22 20:10

Pablo Santa Cruz