Take jboss7.1.0 and MySQL for example
1, find the installation directory, my directory is: jboss-as-7.1.0.cr1b
2, find Standalone.xml, this file on my computer is C:\Users\dan\Desktop\jboss-as-7.1.0.CR1b\standalone\configuration
3, open, and search datasources
4. Make edits
<datasources>
<datasource jndi-name= "java:jboss/datasources/exampleds" pool-name= "Exampleds_pooll"
Enabled= "true" Jta= "true" use-java-context= "true" use-ccm= "true" >
<connection-url>jdbc:mysql://localhost:3306/DBName</connection-url>
<driver>mysql</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>10</max-pool-size>
<prefill>true</prefill>
<use-strict-min></use-strict-min>
</pool>
<security>
<user-name>root</user-name>
<password>123456</password>
</security>
<statement>
<track-statements>true</track-statements>
<prepared-statement-cache-size>10</prepared-statement-cache-size>
</statement>
<timeout>
<idle-timeout-minutes>10</idle-timeout-minutes>
<query-timeout>600</query-timeout>
</timeout>
</datasource>
<drivers>
<driver name= "MySQL" module= "Com.mysql" >
<driver-class>com.mysql.jdbc.Driver</driver-class> <xa-datasource-class> Com.mysql.jdbc2.optional.mysqlxadatasource</xa-datasource-class>
</driver>
</drivers>
</datasources>
5, to the E:\jboss-as-7.1.0.CR1b\modules\com folder under the new MySQL, enter a new main folder in the entry, put the database. Jar in.
6. Create a new Module.xml in this E:\jboss-as-7.1.0.CR1b\modules\com\mysql\main folder
7. Open Module.xml for editing
<module xmlns= "urn:jboss:module:1.1" name= "Com.mysql" >
<resources>
<resource-root path= "Mysql-connector-java-5.0.5-bin.jar"/>
</resources>
<dependencies>
<module name= "Javax.api"/>
<module name= "Javax.transaction.api"/>
</dependencies>
</module>
Remember: path is the same as your database jar
8. Use in the Web
<%
Context c=new InitialContext ();
DataSource datasource= (DataSource) c.lookup ("Java:jboss/datasources/exampleds");
Connection conn=datasource.getconnection ();
PreparedStatement Pstm=null;
ResultSet Rs=null;
try{
Pstm=conn.preparestatement ("Select *from Score");
Rs=pstm.executequery ();
while (Rs.next ()) {
Out.println (Rs.getint (1) + "<br>");
}
}catch (Exception e) {}
%>
jboss7.1.0 configuration database (MySQL)