JBoss: Create database connection

1137150 pts.
Tags:
Database
JBoss
How can I configure a database connection in JBoss? Basically - what do I need in order to make a connection? I know I need a data source configuration. What else?
1

Answer Wiki

Thanks. We'll let you know when a new response is added.
You need two things:

Make the JDBC driver available to your Applications Server
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.


Write a Data Source configuration

<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>



you will find a lot of examples here:
$JBOSS_HOME/docs/examples/jca

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: