如何在JBoss应用服务器中创建DataSource [英] How to create a DataSource in JBoss application server
问题描述
任何人都可以提供使用Oracle数据库在JBoss服务器(5.0)中创建DataSource的步骤。
Can anybody provide the steps for creating DataSource in JBoss server(5.0) with Oracle Database..
提前致谢
推荐答案
此示例假设您使用的是Oracle 10i 。
在JBoss 5中,创建一个以 -ds.xml
结尾的XML文件(虽然不一定是 -ds
,但它必须是XML文件)。使用以下描述符元素。
In JBoss 5, create an XML file ending with -ds.xml
(although not necessarily -ds
, it has to be an XML file). with the following descriptor elements.
这是执行Local-TX数据源的示例。
This is an example to do Local-TX datasource.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE datasources
PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
"http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
<datasources>
<local-tx-datasource>
<jndi-name>MyDataSourceName</jndi-name>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<connection-url>jdbc:oracle:oci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))</connection-url>
<user-name>myUserName</user-name>
<password>myPassword</password>
<min-pool-size>20</min-pool-size>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
您可以拥有超过1 < local-tx-datasource>
元素但是< jndi-name>
必须是唯一的。
You can have more than 1 <local-tx-datasource>
element but <jndi-name>
must be unique.
对于XA数据源,请在此处查看示例。
For XA datasource, see an example here.
以上示例保存在 MyDataSourceName-ds.xml
中。
XML文件必须放在 JBOSS_HOME / server /< default | all> / deploy
文件夹下。
The XML file must be placed under JBOSS_HOME/server/<default|all>/deploy
folder.
现在,在Java中,您将检索 MyDataSourceName
,如下所示:
Now, in Java, you will retrieve MyDataSourceName
as follows:
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:MyDataSourceName");
Connection connection = ds.getConnection();
这篇关于如何在JBoss应用服务器中创建DataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!