JBOSS默认连接池配置
jboss5.0mysql连接配置 <?xml version="1.0" encoding="UTF-8"?> <!-- The Hypersonic embedded database JCA connection factory config --> <!-- $Id: hsqldb-ds.xml 71535 2008-04-01 07:05:03Z adrian@jboss.org $ --> <datasources> <local-tx-datasource> <jndi-name>petstore</jndi-name> <connection-url>jdbc:mysql://localhost:3306/databaseName?characterEncoding=UTF-8</connection-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <user-name>root</user-name> <password>root</password> </local-tx-datasource> </datasources> jboss4.2.1GA oracl配置 1.在$JBOSS_HOME$\server\default\deploy下创建oracle-ds.xml,代码如下: <?xml version="1.0" encoding="UTF-8"?> <datasources> <local-tx-datasource> <jndi-name>jdbc/oracle</jndi-name> <connection-url>jdbc:oracle:thin:@yourserver:1521:youroracleid</connection-url> <driver-class>oracle.jdbc.driver.OracleDriver</driver-class> <user-name>yourusername</user-name> <password>yourpassword</password> <max-pool-size>300</max-pool-size> <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name> </local-tx-datasource> </datasources> 2.在你的web工程下的WEB-INF下的web.xml文件中添加如下代码: <resource-ref> <description>Oracle Connection</description> <res-ref-name>jdbc/oracle</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> 3.在你的web工程下的WEB-INF下新建一个jboss-web.xml文件,代码如下: <?xml version="1.0" encoding="ISO-8859-1"?> <jboss-web> <resource-ref> <description>Oracle Connection</description> <jndi-name>java:jdbc/oracle</jndi-name> <res-ref-name>jdbc/oracle</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </jboss-web> 4.在你的java代码里连接数据库那段代码修改如下: Connection con = null; DataSource datasource = null; Context ctx = new InitialContext(); Context envCtx = (Context) ctx.lookup("java:comp/env"); datasource = (DataSource) envCtx.lookup("java:jdbc/oracle"); con = datasource.getConnection(); 这部分代码是连接jboss连接池的 5.发布工程,重启jboss服务,大功告成。。