First, let's say that you have a web application (or some other application) that is expecting a data source to be present in JNDI. Maybe you have designed the application that needs to support multiple databases (kudos to you). Or maybe the application will be deployed into multiple environments and you do not want to force clients to configure the data source your way with your connection information. Whatever the reason, the data source configured within the container and handed to your application.
Next comes the real easy steps. To configure the data source in jboss, you need to perform 2 steps.
- Drop the JDBC driver jar file into the JBoss classpath. If you're running the 'default' server under JBoss, drop the jar file in $JBOSS_HOME/server/default/lib. JBoss will pick it when the server starts. Here are 2 links to JDBC driver jars:
- PostgreSql
- SQL Server
- Oracle drivers are located under the Oracle installation directory. For 10g, look under C:\oracle\product\10.2.0\db_1\jdbc\lib.
- Create the data source XML file in the deploy directory. Once again, if you're running the 'default' server, create the XML file in $JBOSS_HOME/server/default/deploy. Upon startup, JBoss will load this DS file and configure the data source according to the XML file. Sample XML files for the different DBs are located in the $JBOSS_HOME/docs/examples/jca directory.
- Sample Oracle DS
<datasources>
<local-tx-datasource>
<jndi-name>COP-DS</jndi-name>
<connection-url>jdbc:oracle:thin:@localhost:1521:ORCL</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>user</user-name>
<password>password</password>
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<min-pool-size>2</min-pool-size>
<max-pool-size>5</max-pool-size>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>
</datasources> - Sample SQL Server DS
<datasources>
<local-tx-datasource>
<jndi-name>COP-DS</jndi-name>
<connection-url>jdbc:jtds:sqlserver://localhost:1433/cop</connection-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<user-name>affor</user-name>
<password>password</password>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<min-pool-size>2</min-pool-size>
<max-pool-size>10</max-pool-size>
<metadata>
<type-mapping>MS SQLSERVER2000</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
- Sample Oracle DS
BEWARE: The data source file must be name with '-ds.xml'. That's a dash and NOT an underscore. That little character cost me a few hours of troubleshooting only to be identified by another person.
For more detailed information or for other DB configurations, visit the JBoss wiki on data sources.
7 comments:
<xml>In order to view eXtensible Markup Language in your blog escape less than and greater than signs like so http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php.</xml>
Is there a way to post an entire XML document without having to place greater than & less than signs around every element?
One XML document with multiple elements...ouch.
The only way i've ever posted xml is by escaping the < and > signs as James mentioned.
On a side note, put your xml inside a <pre> tag. This will allow the xml to maintain it's formatting when it shows up on the blog.
Thanx Chad! I've updated the blog to include an XML sample datasource.
Hi, I am new to JBoss and was wondering; under what scenario would one require the use of xa-datasource instead of local-tx-datasource?
Post a Comment