How can we set up a database connection from JBOSS?

Can we set up a database connection with JBOSS? If possible, is there any configuration file in JBOSS to configure the database connection from JBOSS?

+5
source share
3 answers

You need two things:

  • Make the JDBC driver available for your application server
  • Data Source Configuration Record

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

$JBOSS_HOME/server/default/lib

Assuming it $JBOSS_HOMEpoints to your JBoss installation, and you use the installation default.

For # 2 you will find many examples here:

$JBOSS_HOME/docs/examples/jca

. PostgreSQL:

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

, this JBoss.

JDBC ( jar, . db), - . JBoss.

JNDI - . JDBC . JPA, JBoss Hibernate.

0

:

  • sql (,\modules\system\layers\base\com\mysql\main).

  • module.xml , :

<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.0" name="com.mysql">
    <resources>
        <resource-root path="mysql-connector-java-5.1.17-bin.jar"/>
    </resources>

    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.servlet.api" optional="true"/>
    </dependencies>
</module>
  1. stanalone.xml mysql , :
<driver name="mysql" module="com.mysql">
    <driver-class>com.mysql.jdbc.Driver</driver-class>
</driver>
  1. jboss , jboss/bin standalone.bat

  2. localhost: 8080, datasource. "". :

: MysqlDS5

JNDI : java:/mysql

" " mysql.

URL- : jdbc: mysql://localhost: 3306/sampledb

UserName: ****

: ****

, MysqlDS .

, .

0

All Articles