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.