Define and use a datasource under the Websphere Application Server Liberty

Bellow how to define and use a datasource on your workspace.

  1. Create a directory be used as a shared lib for the Oracle JDBC JAR. For example C:\temp_jars and add the ojdbc14.jar and class12.jar to it.
  2. Open server.xml under the Websphere Application Server Liberty Profile and add the bellow two tags:
  3. <dataSource id="oracle" jndiName="jdbc/oracle">
        <jdbcDriver libraryRef="OracleLib"/>
        < URL="jdbc:oracle:thin:@//localhost:1521/test" password="{xor}KzosKw==" user="test"/>
    </dataSource><library description="Oracle JDBC Driver" id="OracleLib" name="Oracle JDBC">
        <fileset dir="C:\temp_jars" includes="ojdbc14.jar class12.jar"/>
  4. Notice that the password attribute is encoded. You can encode the password through a security utility under the Websphere Application Server Liberty Profile bin directory.

    To use this utility to encode the "test" password, follow the bellow commands.
    cd <WLP_PATH>/wlp/bin
    securityUtility encode test
  5. Now inject the datasource at your DAO class as bellow:
  6. import javax.annotation.Resource;
    import javax.ejb.Stateless;
    import javax.sql.DataSource;
    public class TestDAO implements ITestDAO {
        @Resource(lookup = "jdbc/oracle")
        private DataSource ds;
        // ... 


Popular posts from this blog

JavaOne 2015 Session: EJB 3.2/JPA 2.1 Best Practices with Real-Life Examples by Gohar

Spring Core - Different Types of Bean Injection

PrimeFaces Push with Atmosphere