A JDBC connection pool is a group of reusable connections that a web server or application server maintains for a particular database. Applications requesting a connection to a database obtain that connection from the pool. When an application closes a connection, the connection is returned to the pool. Connection pool properties may vary with different database vendors. Some common properties are the URL for the database name, user name, and password.
The first step in creating a database connection pool on the JBoss Application Server is to create JDBC resource (also called a data source). A JDBC resource provides applications with a connection to a database. Typically, there is at least one JDBC resource for each database accessed by an application deployed in a domain. It is possible to have more than one JDBC resource for a database. You can create a JDBC resource manually in a file tailored to your database server, provided in the JBoss installation directory.
To set up a data source on the JBoss Application Server:
<datasources> <local-tx-datasource> <jndi-name>MySqlDS</jndi-name> <connection-url>jdbc:mysql://mysql-hostname:3306/jbossdb</connection-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <user-name>x</user-name> <password>y</password> <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name> <metadata> <type-mapping>mySQL</type-mapping> </metadata> </local-tx-datasource> </datasources>
To reference a data source from a web application:
<resource-ref> <res-ref-name>MySqlDS</res-ref-name> <jndi-name>MySqlDS</jndi-name> </resource-ref>
<resource-ref> <res-ref-name>MySqlDS</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref>
To prepare to use a data source on the JBoss Application Server:
\server\default\deploy\jbossweb.sar\server.xml