Define and use a datasource under the Websphere Application Server Liberty
Bellow how to define and use a datasource on your workspace.
- 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.
- Open server.xml under the Websphere Application Server Liberty Profile and add the bellow two tags:
- 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
- Now inject the datasource at your DAO class as bellow:
<dataSource id="oracle" jndiName="jdbc/oracle"> <jdbcDriver libraryRef="OracleLib"/> <properties.oracle 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"/> </library>
import javax.annotation.Resource; import javax.ejb.Stateless; import javax.sql.DataSource; @Stateless public class TestDAO implements ITestDAO { @Resource(lookup = "jdbc/oracle") private DataSource ds; // ... }
Comments
Post a Comment