Pages

Saturday, July 17, 2010

Configuring a Data Source in Jboss AS 5 [Jboss EWP]

Share it Please

There is many times where an application needs to communicate with a database. Creating a database connection is an expensive operation. So we will make our application server manage the database connection either by creating a data source and providing them to the application whenever the application need it.

So how can we create a data source and deploy that in the Jboss application server,

Create a xml file with extension <some name>-ds.xml (e.g. MyOracle-ds.xml). Data source is defined in the xml file in following way [student-ds.xml]

So in this article, we will be creating a sample data source for accessing a Microsoft access database

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

<datasources>
<local-tx-datasource>
<!-- The jndi name of the DataSource, it is prefixed with java:/ -->
<!-- Datasources are not available outside the virtual machine -->
<jndi-name>StudentDB</jndi-name>
<connection-url>jdbc:odbc:mySource</connection-url>
<!-- The driver class -->
<driver-class>sun.jdbc.odbc.JdbcOdbcDriver</driver-class>
<!-- The login and password -->
<user-name>jagadesh</user-name>
<password>jagadesh</password>
<!-- The minimum connections in a pool/sub-pool.Pools are lazily constructed on first useà
<min-pool-size>5</min-pool-size>
<!-- The maximum connections in a pool/sub-pool -->
<max-pool-size>20</max-pool-size>
</local-tx-datasource>
</datasources>

For creating a data source using Microsoft ODBC, see here

So now we have created the data source file, we need to deploy it .just copy the file in the deploy folder of the server instance you are working on [default].

Once you copy the file, you can check the data source by going to

Admin-console ->Resources -> data sources, and you can see the datasource. You can test the connections and perform various operations on them.

So more articles to come, Happy coding….

No comments :

Post a Comment