Tomcat,jboss,weblogic connecting databases through Jndi

Source: Internet
Author: User
Tags connection pooling jboss tomcat server

    1. 1. Tomcat configuration jndi Data source

1.1 Add a driver jar for the database connection in the Tomcat server's Lib directory

1.2 Modify the Server.xml configuration file in the Conf directory of the Tomcat server

To edit the Server.xml file, add the global Jndi data source configuration, configured as follows:

<GlobalNamingResources>

<resource name= "Userdatabase" auth= "Container"

Type= "Org.apache.catalina.UserDatabase"

description= "User database that can be updated and saved"

factory= "Org.apache.catalina.users.MemoryUserDatabaseFactory"

Pathname= "Conf/tomcat-users.xml"/>

<!--

|-Name: Indicates the names to look for later. This name allows you to find DataSource, which is replaced arbitrarily, but this name is the last thing in the program to look for.

In order not to be confused with the other names, using Jdbc/oracle is now configured with a JDBC naming service for Oracle.

|-AUTH: Authorization and management by the container, whether the user name and password can be effective on the container

|-type: The type represented by this name is now Javax.sql.DataSource

|-maxactive: Indicates the maximum number of connections a database can open on this server

|-Maxidle: Indicates the minimum number of connections that a database maintains on this server

|-maxwait: Maximum wait time. 10000 MS

|-Username: User name for database connection

|-Password: password for database connection

|-driverclassname: Database Connection Driver

|-URL: The address of a database connection

-

<!--Configure the Jndi data source for the MySQL database--

<resource

Name= "Jdbc/mysql"

Auth= "Container[t1]"

Type= "Javax.sql.DataSource"

Maxactive= "100"

Maxidle= "30"

Maxwait= "10000"

Username= "Root"

Password= "Tingyun2o13"

Driverclassname= "Com.mysql.jdbc.Driver"

Url= "Jdbc:mysql://192.168.2.129:3306/javatest"/>

</GlobalNamingResources>

1.3 Open the Context.xml configuration file under Tomcat's Conf directory. (Create ^_^ if not present)

1.3.1 Configuring connection Pooling

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

<!--the contents of this file is loaded for each Web application--

<Context>

<!--Default set of monitored resources. If One of these changes, the--

<!--Web application would be reloaded. -

<WatchedResource>WEB-INF/web.xml</WatchedResource>

<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

<!--Configure a connection pool--

<resourcelink global= "Jdbc/mysql" name= "Jdbc/mysql" type= "Javax.sql.DataSource"/> [T2]

<!--

<resourcelink global= "Jdbc/mysql" name= "Jdbc/mysql" type= "Javax.sql.DataSource"/>

<WatchedResource>WEB-INF/web.xml</WatchedResource>

-

<!--uncomment this to disable session persistence across Tomcat restarts-

<!--

<manager pathname= ""/>

-

</Context>

1.4 Restart Tomcat to access the app through Jndi

Reference blog:

http://blog.csdn.net/samjustin1/article/details/52265803

Http://www.cnblogs.com/xkl520xka/p/5899876.html

    1. 2. Jboss configuration jndi Data source

2.1 First copy the database driver jar file to the Server\default\lib directory (such as MYSQL,ORACLE,DB2, etc.) after the JBoss decompression file

2.2 Find Mysql-ds.xml in DOCS\EXAMPLES\JCA copy the file to the Server\default\deploy directory

2.3 Open Mysql-ds.xml can see the data link configuration, according to their own database modification good configuration, below is my own configuration, you can according to their own database, specific changes

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

<datasources>

<local-tx-datasource>

<jndi-name>DB2DS</jndi-name>

<use-java-context>false</use-java-context>

<connection-url>jdbc:db2://192.168.2.129:50000/test1</connection-url>

<driver-class>COM.ibm.db2.jdbc.app.DB2Driver</driver-class>

<user-name>db2inst1</user-name>

<PASSWORD>NBS2O13</PASSWORD>[T3]

<min-pool-size>0</min-pool-size>

<metadata>

<type-mapping>DB2</type-mapping>

</metadata>

</local-tx-datasource>

</datasources>

2.4 When configured, start JBoss, open the browser, Access http://localhost:8080/jmx-console/, click on the left side of the page JBOSS.JCA, the right side can see

Name= db2ds,service=datasourcebinding

Name= DB2DS,SERVICE=LOCALTXCM

Name= db2ds,service=managedconnectionfactory

Name= Db2ds,service=managedconnectionpool

Indicates that the data source was published successfully

Start JBoss, execute the test, find out that the data source is not available, but our data source is published successfully, after finding the data, we need to add <use-java-context>false</to the published source Mysql-ds.xml. Use-java-context>
The test is then performed, and the test is available, to this JBoss release Jndi data source successfully

Reference blog:

http://sence-qi.iteye.com/blog/1561750

Http://blog.sina.com.cn/s/blog_676015470100oidr.html

[T1] Red for information that needs to be configured

[T2] Red for information that needs to be configured

[T3] Red for the information you want to configure

<use-java-context>false</use-java-context> can not add

Tomcat,jboss,weblogic connecting databases through Jndi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.