WAS v8.5 > Administering applications and their environment > Administering the Liberty profile > Administering the Liberty profile manually > Administering data access applications on the Liberty profile

Configure database connectivity in the Liberty profile


Liberty profile data sources...

Liberty profile requires JDBC drivers to provide at least one of the following types of data sources.

For commonly used JDBC drivers, the Liberty profile is already aware of the implementation class names for the various data source types. You only need to tell the Liberty profile where to find the JDBC driver file on the file system.

  1. Edit server.xml file and define a shared library pointing to the location of the JDBC driver. For example:

    < library id="DB2JCC4Lib"> 
        < fileset dir="C:/DB2/java" 
                 includes="db2jcc4.jar 
                 db2jcc_license_cisuz.jar"/> 
    </library>

  2. Define a data source using the JDBC driver.

    If we don't specify the type of data source, the Liberty profile chooses in the following order depending on which is available.

    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>

  3. Optional: Configure attributes for the data source, such as JDBC vendor properties and connection pooling properties.

    For example:

    < dataSource id="db2" 
                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>

  4. Optional: Configure data sources for commonly used databases according to the following examples.

    For DB2

    < dataSource id="db2" 
                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="db2iNative" 
                jndiName="jdbc/db2iNative"> 
        < jdbcDriver libraryRef="DB2iNativeLib"/>     < properties.db2.i.native databaseName="*LOCAL"/> 
    </dataSource> 
    < library>     < fileset dir="/QIBM/Proddata/java400/jdk6/lib/ext" 
                 includes="db2_classes16.jar"/> </library>

    For DB2 on iSeries (Toolbox)

    < dataSource 
                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 
                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 
                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 
                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="informix" 
                jndiName="jdbc/informix"> 
        < jdbcDriver libraryRef="InformixLib"/>     < properties.informix databaseName="SAMPLEDB" ifxIFXHOST="localhost" 
                             serverName="ol_machinename" portNumber="1526"/> </dataSource> 
    < library>     < fileset dir="C:/Drivers/informix" 
                 includes="ifxjdbc.jar ifxjdbcx.jar"/> </library>

    For Microsoft SQL Server (Microsoft JDBC driver)

    < dataSource 
                jndiName="jdbc/mssqlserver"> 
        < jdbcDriver libraryRef="MSJDBCLib"/>     < properties.microsoft.sqlserver databaseName="SAMPLEDB" 
                                        serverName="localhost" portNumber="1433"/> </dataSource> 
    < library >     < fileset dir="C:/sqljdbc_4.0/enu" 
                 includes="sqljdbc4.jar"/> </library>

    For Microsoft SQL Server (DataDirect Connect for JDBC driver)

    < dataSource 
                jndiName="jdbc/ddsqlserver"> 
        < jdbcDriver libraryRef="DataDirectLib"/>     < properties.datadirect.sqlserver databaseName="SAMPLEDB" 
                                         serverName="localhost" portNumber="1433"/> </dataSource> 
    < library>     < fileset dir="C:/DataDirect/Connect-4.2/lib" 
                 includes="sqlserver.jar"/> </library>

    For MySQL

    < dataSource id="mySQL" 
                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" 
                 includes="mysql-connector-java-x.x.xx.jar"/> </library>

    For Oracle

    < dataSource id="oracle" 
                jndiName="jdbc/oracle"> 
        < jdbcDriver libraryRef="OracleLib"/>     < properties.oracle URL="jdbc:oracle:thin:@//localhost:1521/SAMPLEDB"/> </dataSource> 
    < library >     < fileset dir="C:/Oracle/lib" includes="ojdbc6.jar"/> </library>

    For Sybase

    < dataSource id="sybase" 
                jndiName="jdbc/sybase"> 
        < jdbcDriver libraryRef="SybaseLib"/>     < properties.sybase databaseName="SAMPLEDB" serverName="localhost" portNumber="5000"/> </dataSource> 
    < library >     < fileset dir="C:/Drivers/sybase" includes="jconn4.jar"/> </library>

    For solidDB

    < dataSource id="solidDB" 
                jndiName="jdbc/solidDB"> 
        < jdbcDriver libraryRef="solidLib"/>     < properties databaseName="SAMPLEDB" URL="jdbc:solid://localhost:2315/"/> </dataSource> 
    < library id="solidLib">     < fileset dir="C:/Drivers/solidDB" includes="SolidDriver2.0.jar"/> </library>

    For a JDBC driver not known to the Liberty profile

    < dataSource id="sample" 
                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/" includes="sampleDriver.jar"/> </library>
    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.

See also


Parent topic: Administering data access applications on the Liberty profile


Related

Configuring session persistence for the Liberty profile


|