设为首页 收藏本站
查看: 573|回复: 0

[经验分享] How to create Oracle DataSource And Install Oracle JDBC Driver in JBoss AS7

[复制链接]

尚未签到

发表于 2016-7-25 13:10:54 | 显示全部楼层 |阅读模式
Hi,
DSC0000.png Unlike JBoss AS 6 there is no “$PROFILE/lib” present in JBoss AS 7 where we can place our JDBC Drivers in order to add/register the JDBC Driver. Also in JBoss AS 7 we don’t need to create a separate DataSource file as “*-ds.xml” file.
In JBoss AS 7 the DataSource configuration is placed wither inside the “Jboss-as-7.0.1.Final/standalone/configuration/standalone.xml” (if you are running a JBoss standalone profile), or the datasource information is placed inside the “boss-as-7.0.1.Final/domain/configuration/domain.xml” file.Here in this demonstration we will see how to install/register a JDBC Driver in JBoss AS7 and then how to create a DataSource from Admin-Console.
  You can have a look at the below article for creating MySql Datasource
How to create MySql DataSource And Install MySql JDBC Driver in JBoss AS7
  There are two options to install/Register a JDBC Driver to JBoss AS 7.
1). Installing a JDBC driver as a deployment
2). Installing a JDBC driver as a module


Installing a JDBC driver as a deployment
  First we need to check which Jdbc Driver are we using? Is it a JDBC 4-compliant driver or a Non-JDBC 4 -compliant driver? Any JDBC 4-compliant driver will automatically be recognized and installed into the system by name and version. A JDBC 4-compliant JAR is identified using the Java service provider mechanism. It contains a text a file named “META-INF/services/java.sql.Driver”, which contains the name of the class(es) of the Drivers which exist in that JAR.
  If the driver is already JDBC4-comliant then you can directly deploy it inside the “jboss-as-7.0.1.Final/standalone/deployments” based on the mode which you are using to run your JBoss AS.

Dealing with Non JDBC 4 -compliant Drivers:
  If your JDBC Driver is NOT JDBC 4-compliant then we can update the driver using “jar” utility by adding the “META-INF/services/java.sql.Driver” inside it. as following:
Step1). Create a directory somewhere in your file system like “/home/userone/testDriver”
Step2). Place your Non-JDBC 4 compliant driver in this directory “/home/userone/testDriver” suppose your Driver Jar name is “YourJdbcDriver.jar”
Step3). Now create “META-INF/services” directory inside “/home/userone/testDriver”
Step4). Create a file with name “java.sql.Driver” inside “/home/userone/testDriver/META-INF/services” directory and then add the fully qualified name of your JDBC Driver class in this file.
Step5). use the jar utility with -u (means update) option to add the META-INF directory with the above contents in it as following

jar  -uf  YourJdbcDriver.jar  META-INF/services/java.sql.Driver

  Now you can take your JDBC Driver and then place it inside the “${JBOSS_AS7}/standalone/deployments”.
The advantage of deploying the JDBC Driver as a deployment in “domain” mode is that the deployments are automatically propagated to all servers to which the deployment applies, so the administrator need not to worry about the the JDBC Driver distribution every time.

Installing a JDBC driver as a module
  This is another option to install the JDBC Driver as a module. Which requires that we define a new module for our JDBC Driver inside “${JBOSS_AS7}/modules” directory as following:
Suppose if we want to install the Oracle JDBC Driver (ojdbc6.jar) then we will need to do the following steps:
Step1). Create a directory “oracle/jdbc/main” inside the “jboss-as-7.0.1.Final/modules” directory.
Step2). paste your “ojdbc6.jar” oracle Jdbc Driver inside “jboss-as-7.0.1.Final/modules/oracle/jdbc/main” directory.
Step3). Create a file “module.xml” inside “jboss-as-7.0.1.Final/modules/oracle/jdbc/main” as following:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="oracle.jdbc">
<resources>
<resource-root path="ojdbc6.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>

  Step4). Now open your “jboss-as-7.0.1.Final/standalone/configuration/standalone.xml” file or “jboss-as-7.0.1.Final/domain/configuration/domain.xml” file and then add the driver declaration tag refering to your module as following, by default you will see the driver declaration tag already contains the declaration for <driver name=”h2″ module=”com.h2database.h2″>:

                <drivers>
<driver name="OracleJDBCDriver" module="oracle.jdbc" />
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>
org.h2.jdbcx.JdbcDataSource
</xa-datasource-class>
</driver>
</drivers>

  Here we declared the <driver name=”OracleJDBCDriver” module=”oracle.jdbc”/>
  Step5). Create a DataSource in your JBoss AS 7 and then in the Driver section you can refer to this Module name “oracle.jdbc”

Creating a DataSource from JBoss AS 7 Admin Console
  Step1). After installing the JDBC Driver as mentioned above start your JBoss AS 7 and then login to the admin-console from URL: “http://localhost:9990/console” (as admin/admin credentials)
Step2). From left hand panel of the console click on “Connectors—>DataSources”

DSC0001.png
Creating Oracle DataSource in AS7


  Step3). In the right side panel you will see a button “Add” click on this button.
Step4). In Wizard “Step 1/3: Datasource Attributes”
Enter the DataSource Name as “OracleDS”
Enter JNDI Name as “java:/OracleDSJNDI” or “java:jboss/OracleDSJNDI” (NOTE the valid DataSource name should start with either java:/ or with java:jboss/ prefix)

DSC0002.png
DataSource name & JNDI Name


  Step5). Now in the next Section “Step 2/3: JDBC Driver” you will see all the installed drivers details. in above case as we already registered oracle driver as a module “OracleJDBCDriver” in previous section so we will be able to see the details as following:

DSC0003.png
Registered Jdbc Drivers List


  Step6). In next section “” provide the Database url (jdbc:oracle:thin:@10.10.10.10:1521:DB_SID) ,username and password

DSC0004.png
Specifying DataSource properties


  Step7). you will see following kind of messae in your JBoss AS 7 console output:


DataSource Details



10:50:32,330 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) Bound data source [OracleDSJNDI]

  For More Details visit:
https://docs.jboss.org/author/display/AS7/Developer+Guide
http://community.jboss.org/wiki/DataSourceConfigurationinAS7#Installing_a_JDBC_driver_as_a_deployment
.
.
Thanks
MiddlewareMagic Team

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-249260-1-1.html 上篇帖子: 冷备份/还原Oracle数据库 以及 Oracle 10g的Enterprise Manager登陆问题 下篇帖子: oracle dba应该定期做什么!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表