JBoss set up the data source and test page-jboss5.0.1

Source: Internet
Author: User
Tags rar stmt jboss

http://www.miotour.com/2010/06/11/jboss%E8%AE%BE%E7%BD%AE%E6%95%B0%E6%8D%AE%E6%BA%90%E5%92%8C%E6%B5%8B%E8%AF% 95%e9%a1%b5%e9%9d%a2/

JBoss Set the data source and test page-jboss5.0.1 Posted in June 11, 2010 ¬17:24h. Admin comment off

Steps:

1, set the data source configuration file

2, add the database driver to JBoss's lib package, under jboss_home/server/xxxx/lib/

3, test the database connection, if named Miotour, then use is java:/miotour

DataSource ds = (DataSource) ctx.lookup ("Java:/miotour");

First, it needs to be explained that there are two types of data sources for Jboss.



As you can see from the screenshot, there are two types of data sources in the data source section.

Local-tx-datasource

No-tx-datasource

Xa-datasource

The data source configuration template for various databases is available in the DOCS/EXAMPLES/JCA of Jboss

Data source configuration files are always named *-ds.xml files local-tx-datasource-– only support local transactions

This is the most commonly used, configure the Localtxconnectionmanager service, which only supports "local transaction", specifically, a transaction that supports only one data source, and does not support distributed transactions, not local to the database specified by the data source. can be anywhere, but Local-tx-datasource cannot access two data sources in one transaction, even if the two data source configurations are the same. xa-datasource-– Distributed Transactions

The data source configures the Xatxconnectionmanager service. XA transactions are also commonly referred to as distributed transactions. There can be multiple resources (such as data sources) in a transaction, but these resources must be able to support XA transactions, and the database that supports XA transactions has a xa-ds.xml file in the DOCS/EXAMPLES/JCA directory

So, I'm offering you a local-tx-datasource default profile.

Download Address: Http://download.miotour.com/jboss/dataosource/miotour-ds.zip

Download Address: Http://download.miotour.com/jboss/dataosource/test.zip

Configuration file: Remove the red part need to set, the rest is JBoss automatically add <?xml version= "1.0″encoding=" utf-8″standalone= "yes"?> <datasources> < Local-tx-datasource > <jndi-name> miotour </jndi-name> <rar-name> jboss-local-jdbc.rar</ Rar-name> <use-java-context>true</use-java-context> <connection-definition> Javax.sql.datasource</connection-definition> <jmx-invoker-name> jboss:service=invoker,type=jrmp</ Jmx-invoker-name> <min-pool-size>0</min-pool-size> <max-pool-size>10</max-pool-size> <blocking-timeout-millis>30000</blocking-timeout-millis> <idle-timeout-minutes>30</ Idle-timeout-minutes> <prefill>false</prefill> <background-validation>false</ Background-validation> <background-validation-millis>0</background-validation-millis> < Validate-on-match>true</validate-on-match> <statistics-formatter>org. JBoss. Resource.statistic.pool.JBossDefaultSubPoolStAtisticformatter</statistics-formatter> <issamerm-override-value>false</issamerm-override-value > <allocation-retry>0</allocation-retry> <allocation-retry-wait-millis>5000</ allocation-retry-wait-millis> <security-domain xsi:type= "Securitymetadata" xmlns:xsi= "http://www.w3.org/" 2001/xmlschema-instance "/> <metadata> <type-mapping>Oracle9i</type-mapping> </metadata > <type-mapping>Oracle9i</type-mapping> <local-transaction/> <user-name> miotour </ user-name> <password> miotour </password> <check-valid-connection-sql>select * from dual</ Check-valid-connection-sql> <exception-sorter-class-name>org. JBoss. Resource.adapter.jdbc.vendor.oracleexceptionsorter</exception-sorter-class-name> < Prepared-statement-cache-size>0</prepared-statement-cache-size> <share-prepared-statements>false </share-prepared-statements> <set-tx-query-timeout>false</set-tx-query-timeout> <query-timeout>0</query-timeout> <use-try-lock>60000</ Use-try-lock> <driver-class>oracle.jdbc.driver.OracleDriver</driver-class> <connection-url> jdbc:oracle:thin:@10.10.10.10:1521:miotour</connection-url> </local-tx-datasource > </datasources >

2, test the file of the database

<%@ page contenttype= "text/html;charset=utf-8″%>

<%@ page import= "java.sql.*"%>

<%@ page import= "javax.sql.*"%>

<%@ page import= "javax.naming.*"%>

<body>

<% Context ctx = new InitialContext ();

Connection Conn=null;

CTX = new InitialContext ();

DataSource ds = (DataSource) ctx.lookup ("Java:/miotour");

conn = Ds.getconnection ();

Statement stmt=conn.createstatement (resultset.type_scroll_sensitive,resultset.concur_updatable);

String sql= "SELECT * from Vender";

ResultSet rs=stmt.executequery (SQL);

%>

<% while (Rs.next ()) {

Out.println (rs.getstring (1));

Out.println (rs.getstring (2));

Out.println (Rs.getstring (3));

}

%>

<% out.print ("successed"). ”);

Rs.close ();

Stmt.close ();

Conn.close ();

%>

</body>

In the spring configuration file
<!--set Use-java-context to False in Mysql-ds.xml, note that there is no prefix java:-->
< Jee:jndi-lookup ID = "DataSource" jndi-name = "Dabase1"/>
< Bean id = "Txmanager"
class = "Org.springframework.transaction.jta.JtaTransactionManager" >
<!--manually injected, otherwise it will report TransactionManager not bound-->
< property name = "transactionmanagername " value = "java:/transactionmanager "/>
</Bean >

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.