Microsoft JDBC driver with multiple DataSource implementations
vinfang Apr 25, 2012 10:40 PMI'm trying to setup the JDBC driver and data sources in the application server using Microsoft's JDBC Driver 4.0 for SQL Server http://msdn.microsoft.com/en-us/sqlserver/aa937724
I'm deploying the sqljdbc4.jar in the standalone/deployments directory, and I'm logging on to the web administrative console to setup the datasource to point to the correct driver while giving it a JNDI name, pool name, and connection parameters. So far testing the connection works and there aren't any problems. My only confusion is that stated in Microsoft Documentation http://msdn.microsoft.com/en-us/library/ms378729.aspx it says they implemented all 3 types of DataSources: DataSource, ConnectionPoolDataSource, and XADataSource.
Looking at my standalone.xml configuration file
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jta="false" jndi-name="java:/jdbc/DataSource" pool-name="MicrosoftDataSource" enabled="true" use-ccm="false">
<connection-url>jdbc:sqlserver://localhost\SQLEXPRESS:1433</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<driver>sqljdbc4.jar</driver>
<security>
<user-name>test</user-name>
<password>test</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
How does it know which type of DataSource to use? I haven't written any code to do a Context.lookup() yet but since I can only specify the jndi-name, I know I'm getting a DataSource back but I don't know what kind of DataSource it is.
Can I modify the .xml file to this and be able to specify which DataSource implementation I wish to choose?
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jta="false" jndi-name="java:/jdbc/DataSource" pool-name="MicrosoftDataSource" enabled="true" use-ccm="false">
<connection-url>jdbc:sqlserver://localhost\SQLEXPRESS:1433</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<datasource-class>com.microsoft.sqlserver.jdbc.SQLServerDataSource</datasource-class>
<driver>sqljdbc4.jar</driver>
<security>
<user-name>test</user-name>
<password>test</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
Looking at this reference page, http://docs.jboss.org/ironjacamar/userguide/1.0/en-US/html/deployment.html#deployingds_descriptor, it mentions a <datasource-class> I could use but I'm not sure if this is the right way to do it.