jboss-4.2.2.GA中配置数据源详细步骤
2008-05-09 11:26
871 查看
最近使用jboss-4.2.2.GA版本配置数据源,略有心得,特发此篇,希望对还在迷茫的同学有帮助!
各种类型的数据库,都可以根据%JBOSS_HOME%/docs/examples/jca/下的示例文档配置,
下面以mssql为例,提供我们在生产机环境的配置。
该xml文件存在于%JBOSS_HOME%/docs/examples/jca/下的mssql-ds.xml,
修改文件内容形如
<datasources>
<local-tx-datasource>
<jndi-name>dataSource</jndi-name>
<connection-url>jdbc:microsoft:sqlserver://localost:1433;DatabaseName=jcwork</connection-url>
<driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
<user-name>sa</user-name>
<password></password>
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>MS SQLSERVER2000</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
然后将其拷贝至%JBOSS_HOME%/server/all(or default)/deploy/下,
对应的数据库驱动程序jar需copy至部署的配置的lib下,本例中就要拷贝mssqlserver.jar,msbase.jar,msutil.jar到该目录下
以下是在jsp页面中测试该数据源的代码
Context ctx=null;
Connection cnn=null;
java.sql.Statement stmt=null;
ResultSet rs=null;
try
{
ctx=new InitialContext();
if(ctx==null)
throw new Exception("initialize the Context failed");
DataSource ds=(DataSource)ctx.lookup("java:dataSource");
out.println(ds);
if(ds==null)
throw new Exception("datasource is null");
try{
cnn=ds.getConnection();
out.println("<br> connection:"+cnn+"你已经成功得到了数据源!");
}catch(Exception e){
e.printStackTrace();
}
}
finally
{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(cnn!=null)
cnn.close();
if(ctx!=null)
ctx.close();
}
之后启动jboss服务,如果一切顺利可以看到如下输出:
org.jboss.resource.adapter.jdbc.WrapperDataSource@10d78ec
connection:org.jboss.resource.adapter.jdbc.WrappedConnection@1ccf342你已经成功得到了数据源!
各种类型的数据库,都可以根据%JBOSS_HOME%/docs/examples/jca/下的示例文档配置,
下面以mssql为例,提供我们在生产机环境的配置。
该xml文件存在于%JBOSS_HOME%/docs/examples/jca/下的mssql-ds.xml,
修改文件内容形如
<datasources>
<local-tx-datasource>
<jndi-name>dataSource</jndi-name>
<connection-url>jdbc:microsoft:sqlserver://localost:1433;DatabaseName=jcwork</connection-url>
<driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
<user-name>sa</user-name>
<password></password>
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>MS SQLSERVER2000</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
然后将其拷贝至%JBOSS_HOME%/server/all(or default)/deploy/下,
对应的数据库驱动程序jar需copy至部署的配置的lib下,本例中就要拷贝mssqlserver.jar,msbase.jar,msutil.jar到该目录下
以下是在jsp页面中测试该数据源的代码
Context ctx=null;
Connection cnn=null;
java.sql.Statement stmt=null;
ResultSet rs=null;
try
{
ctx=new InitialContext();
if(ctx==null)
throw new Exception("initialize the Context failed");
DataSource ds=(DataSource)ctx.lookup("java:dataSource");
out.println(ds);
if(ds==null)
throw new Exception("datasource is null");
try{
cnn=ds.getConnection();
out.println("<br> connection:"+cnn+"你已经成功得到了数据源!");
}catch(Exception e){
e.printStackTrace();
}
}
finally
{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(cnn!=null)
cnn.close();
if(ctx!=null)
ctx.close();
}
之后启动jboss服务,如果一切顺利可以看到如下输出:
org.jboss.resource.adapter.jdbc.WrapperDataSource@10d78ec
connection:org.jboss.resource.adapter.jdbc.WrappedConnection@1ccf342你已经成功得到了数据源!
相关文章推荐
- jboss5.0配置数据源详细步骤
- JBoss7.1配置Oracle11g数据源,详细图解
- JBoss7.1配置Oracle11g数据源,详细图解
- Jboss的JDBC数据源配置步骤详解大全
- VS2010 DDK编译驱动程序 环境配置详细步骤
- centos 5 yum安装与配置vsFTPd FTP服务器详细步骤
- mysql5.6版本-主从复制配置详细步骤
- centos配置nfs服务详细步骤(centos开启nfs服务)
- Jboss数据源配置
- Git + TortoiseGit 配置超详细步骤
- Java项目开发中Eclipse新建工作空间后的配置详细步骤
- Xcode配置SVN详细步骤
- Ubuntu JDK安装配置的详细步骤:
- Hibernate中配置C3P0数据源步骤及hbm.xml 文件详解
- 详细配置公司内部网络环境步骤
- ODBC的配置及其连接的详细步骤
- centos配置nfs服务详细步骤(centos开启nfs服务)
- Ubuntu Linux配置Nginx+MySQL+PHP+phpMyAdmin详细步骤
- Linux远程登录访问win 7系统详细配置步骤
- 如何在jboss中配置数据源