Configuring relational database connectivity in Liberty
You can configure a data source associated with different JDBC providers for database connectivity. The JDBC providers supply the driver implementation classes that are required for JDBC connectivity with your specific vendor database.
About this task
- javax.sql.DataSource
This is the basic form of a data source. It does not provide interoperability that enhances connection pooling, and cannot participate as a two-phase capable resource in transactions involving multiple resources.
- javax.sql.ConnectionPoolDataSource
This type of data source is enabled for connection pooling. It cannot participate as a two-phase capable resource in transactions involving multiple resources.
- javax.sql.XADataSource
This type of data source is both enabled for connection pooling and is able to participate as a two-phase capable resource in transactions involving multiple resources.
In order to be usable in the Liberty, your JDBC driver must provide at least one of these types of data sources. For the commonly used JDBC drivers, Liberty is already aware of the implementation class names for the various data source types. You only need to tell Liberty where to find the JDBC driver.
Procedure
- In the server.xml file, define a shared
library pointing to the location of your JDBC driver JAR or compressed
files. For example:
<library id="DB2JCC4Lib"> <fileset dir="C:/DB2/java" includes="db2jcc4.jar db2jcc_license_cisuz.jar"/> </library>
- Define a data source using the JDBC driver. If you don't specify the type of
data source, Liberty chooses the data source in the following order depending on
which is available.
- javax.sql.ConnectionPoolDataSource
- javax.sql.DataSource
- javax.sql.XADataSource
Here is an example that accepts the default for data source type:<dataSource id="db2" jndiName="jdbc/db2"> <jdbcDriver libraryRef="DB2JCC4Lib"/> <properties.db2.jcc databaseName="SAMPLEDB" serverName="localhost" portNumber="50000"/> </dataSource>
Here is an example that uses javax.sql.XADataSource type:<dataSource id="db2xa" jndiName="jdbc/db2xa" type="javax.sql.XADataSource"> <jdbcDriver libraryRef="DB2JCC4Lib"/> <properties.db2.jcc databaseName="SAMPLEDB" serverName="localhost" portNumber="50000"/> </dataSource>
A default data source is available when at least one Java EE 7 feature is enabled. This data source uses a different priority to determine the type if none is specified.- javax.sql.XADataSource
- javax.sql.ConnectionPoolDataSource
- javax.sql.DataSource
This data source is available as java:comp/DefaultDataSource. A jndiName does not need to be specified for it. To configure the default data source, specify a data source with the id set to DefaultDataSource. Here is an example that configures the default data source to point at a DB2 database:<dataSource id="DefaultDataSource"> <jdbcDriver libraryRef="DB2JCC4Lib"/> <properties.db2.jcc databaseName="SAMPLEDB" serverName="localhost" portNumber="50000"/> </dataSource>
- Optional: Configure attributes for the data source, such as JDBC vendor
properties and connection pooling properties. For example:
<dataSource id="DefaultDataSource" jndiName="jdbc/db2" connectionSharing="MatchCurrentState" isolationLevel="TRANSACTION_READ_COMMITTED" statementCacheSize="20"> <connectionManager maxPoolSize="20" minPoolSize="5" connectionTimeout="10s" agedTimeout="30m"/> <jdbcDriver libraryRef="DB2JCC4Lib"/> <properties.db2.jcc databaseName="SAMPLEDB" serverName="localhost" portNumber="50000" currentLockTimeout="30s" user="user1" password="pwd1"/> </dataSource>
For a full list of configuration attributes for the dataSource element, connectionManager element and some commonly used JDBC vendors, see Data Source (dataSource).
- Optional: Configure data sources for commonly
used databases according to the following examples.
- For DB2®
<dataSource id="DefaultDataSource" jndiName="jdbc/db2"> <jdbcDriver libraryRef="DB2JCC4Lib"/> <properties.db2.jcc databaseName="SAMPLEDB" serverName="localhost" portNumber="50000"/> </dataSource> <library id="DB2JCC4Lib"> <fileset dir="C:/DB2/java" includes="db2jcc4.jar db2jcc_license_cisuz.jar"/> </library>
- For DB2 on iSeries (Native)
<dataSource id="DefaultDataSource" jndiName="jdbc/db2iNative"> <jdbcDriver libraryRef="DB2iNativeLib"/> <properties.db2.i.native databaseName="*LOCAL"/> </dataSource> <library id="DB2iNativeLib"> <fileset dir="/QIBM/Proddata/java400/jdk6/lib/ext" includes="db2_classes16.jar"/> </library>
- For DB2 on iSeries (Toolbox)
<dataSource id="DefaultDataSource" jndiName="jdbc/db2iToolbox"> <jdbcDriver libraryRef="DB2iToolboxLib"/> <properties.db2.i.toolbox databaseName="SAMPLEDB" serverName="localhost"/> </dataSource> <library id="DB2iToolboxLib"> <fileset dir="/QIBM/ProdData/Http/Public/jt400/lib" includes="jt400.jar"/> </library>
- For Derby Embedded
<dataSource id="DefaultDataSource" jndiName="jdbc/derbyEmbedded"> <jdbcDriver libraryRef="DerbyLib"/> <properties.derby.embedded databaseName="C:/databases/SAMPLEDB" createDatabase="create"/> </dataSource> <library id="DerbyLib"> <fileset dir="C:/db-derby-10.8.1.2-bin/lib"/> </library>
- For Derby Network Client
<dataSource id="DefaultDataSource" jndiName="jdbc/derbyClient"> <jdbcDriver libraryRef="DerbyLib"/> <properties.derby.client databaseName="C:/databases/SAMPLEDB" createDatabase="create" serverName="localhost" portNumber="1527"/> </dataSource> <library id="DerbyLib"> <fileset dir="C:/db-derby-10.8.1.2-bin/lib"/> </library>
- For Informix® JCC
<dataSource id="DefaultDataSource" jndiName="jdbc/informixjcc"> <jdbcDriver libraryRef="DB2JCC4Lib"/> <properties.informix.jcc databaseName="SAMPLEDB" serverName="localhost" portNumber="1526"/> </dataSource> <library id="DB2JCC4Lib"> <fileset dir="C:/Drivers/jcc/4.8" includes="db2jcc4.jar db2jcc_license_cisuz.jar"/> </library>
- For Informix JDBC
<dataSource id="DefaultDataSource" jndiName="jdbc/informix"> <jdbcDriver libraryRef="InformixLib"/> <properties.informix databaseName="SAMPLEDB" ifxIFXHOST="localhost" serverName="ol_machinename" portNumber="1526"/> </dataSource> <library id="InformixLib"> <fileset dir="C:/Drivers/informix" includes="ifxjdbc.jar ifxjdbcx.jar"/> </library>
- For Microsoft SQL Server (Microsoft JDBC driver)
<dataSource id="DefaultDataSource" jndiName="jdbc/mssqlserver"> <jdbcDriver libraryRef="MSJDBCLib"/> <properties.microsoft.sqlserver databaseName="SAMPLEDB" serverName="localhost" portNumber="1433"/> </dataSource> <library id="MSJDBCLib"> <fileset dir="C:/sqljdbc_6.0/enu/sqljdbc41.jar"/> </library>
- For Microsoft SQL Server (DataDirect Connect for JDBC driver)
<dataSource id="DefaultDataSource" jndiName="jdbc/ddsqlserver"> <jdbcDriver libraryRef="DataDirectLib"/> <properties.datadirect.sqlserver databaseName="SAMPLEDB" serverName="localhost" portNumber="1433"/> </dataSource> <library id="DataDirectLib"> <fileset dir="C:/DataDirect/Connect-4.2/lib/sqlserver.jar"/> </library>
- For MySQL
<dataSource id="DefaultDataSource" jndiName="jdbc/mySQL"> <jdbcDriver libraryRef="MySQLLib"/> <properties databaseName="SAMPLEDB" serverName="localhost" portNumber="3306"/> </dataSource> <library id="MySQLLib"> <fileset dir="C:/mysql-connector-java-x.x.xx/mysql-connector-java-x.x.xx.jar"/> </library>
- For Oracle
<dataSource id="DefaultDataSource" jndiName="jdbc/oracle"> <jdbcDriver libraryRef="OracleLib"/> <properties.oracle URL="jdbc:oracle:thin:@//localhost:1521/SAMPLEDB"/> </dataSource> <library id="OracleLib"> <fileset dir="C:/Oracle/lib/ojdbc6.jar"/> </library>
- For Sybase
<dataSource id="DefaultDataSource" jndiName="jdbc/sybase"> <jdbcDriver libraryRef="SybaseLib"/> <properties.sybase databaseName="SAMPLEDB" serverName="localhost" portNumber="5000"/> </dataSource> <library id="SybaseLib"> <fileset dir="C:/Drivers/sybase/jconn4.jar"/> </library>
- For solidDB®
<dataSource id="DefaultDataSource" jndiName="jdbc/solidDB"> <jdbcDriver libraryRef="solidLib"/> <properties databaseName="SAMPLEDB" URL="jdbc:solid://localhost:2315/"/> </dataSource> <library id="solidLib"> <fileset dir="C:/Drivers/solidDB/SolidDriver2.0.jar"/> </library>
- For a JDBC driver that is not known to Liberty
In the example, the JDBC driver is located at C:/Drivers/SampleJDBC/sampleDriver.jar and provides an implementation of javax.sql.XADataSource named com.ibm.sample.SampleXADataSource. The JDBC driver also provides vendor-specific data source properties such as databaseName, hostName and port.<dataSource id="DefaultDataSource" jndiName="jdbc/sample" type="javax.sql.XADataSource"> <jdbcDriver libraryRef="SampleJDBCLib" javax.sql.XADataSource="com.ibm.sample.SampleXADataSource"/> <properties databaseName="SAMPLEDB" hostName="localhost" port="12345"/> </dataSource> <library id="SampleJDBCLib"> <fileset dir="C:/Drivers/SampleJDBC/sampleDriver.jar"/> </library>
Subtopics
Configuring a default data source
You can configure a default data source that is associated with different JDBC providers for database connectivity. The JDBC providers supply the driver implementation classes that are required for JDBC connectivity with your specific vendor database.- How data source configuration updates are applied
If you change the attributes of the dataSource element while a server is running, the updates to different attributes are applied at different times and in different ways. - Application-defined data sources
You can define a data source within your application, through annotations or in the deployment descriptor, as defined by the Java™ EE specification. Configuring client reroute for applications that use DB2 databases
You can use the client reroute feature to configure your enterprise applications for a DB2 database to recover from a communication loss, and the applications can continue to work with minimal interruption. Rerouting is central to the support of continuous operations, but rerouting is only possible when there is an alternative location that is identified to the application server connection.- Configuring connection pooling for database connections
You can configure connection pooling for your data source by defining a connection manager for it.


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-libcore-mp&topic=twlp_dep_configuring_ds
File name: twlp_dep_configuring_ds.html