Detailed steps for configuring a data source in Jboss-4.2.2.ga

Source: Internet
Author: User
Tags mssql stmt jboss

Recently using the Jboss-4.2.2.ga version of the data source configuration, a little experience, special hair This article, I hope the students are still confused help.

Various types of databases can be configured according to the sample document under%jboss_home%/docs/examples/jca/,
The following is an example of MSSQL to provide our configuration in the production machine environment.
The XML file exists in the Mssql-ds.xml under%jboss_home%/docs/examples/jca/,
Modify the contents of a file like < 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 a existing pooled connection when it was 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 >

It is then copied to the%jboss_home%/server/all (or default)/deploy/,
The corresponding database driver jar should be copied to the configured lib of the deployment, in this case, copy Mssqlserver.jar,msbase.jar,msutil.jar to the directory
The following is the code context for testing the data source in the JSP page 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 +") You have successfully obtained the data source. " );
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 ();
}

After starting the JBoss service, if all goes well you can see the following output:
Org.jboss.resource.adapter.jdbc.wrapperdatasource@10d78ec
connection:org.jboss.resource.adapter.jdbc.wrappedconnection@1ccf342 you have successfully obtained the data source.

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.