Legacy Data Base (Informix 11.5 RDBMS)connection & retrieval of data in Liferay 6.2 CE

Informix Dynamic Server

Informix Dynamic Server, also known as IDS, is an extensible Relational Database Management System originally developed by Informix Software Inc. IDS is now part of the IBM Software Group database portfolio.

Use the below link to download Informix 11.5 server and need to register.

How to Install and Configure Informix Dynamic Server ...?

Please refer the link

once the configuration completed we need to create a database "matrade". Create tables r_state & company (for table columns refer below service.xml) within matrade dbase to carry out below example. Insert some data in both tables. You can refer IBM Informix manual to create a database and table.

How to Configuring Informix in liferay ...?

1)  We need ifxjdbc.jar file and place it in 'tomcat/webapps/ROOT/WEB-INF/lib' so that accessible by all portlet. you can get this from

2)  Make the following entries inside the "" under PORTAL_HOME for our custom Informix data base.


jdbc.custom.default.url= jdbc:informix-sqli://host-name:port-number/dbName:INFORMIXSERVER=serverName

jdbc.custom.default.username=username of server instance jdbc.custom.default.password=password of server server


host-name - server name or IP Address of the remote server

port-number - port number of informix server

dbName - name of the database going to be connect

serverName - name given to the server during configuration

username & password  - is the one given during configuring Informix



########### Liferay Portal Informix Local Database Configuration ########## jdbc.custom.default.driverClassName=com.informix.jdbc.IfxDriver


jdbc.custom.default.username= *******

jdbc.custom.default.password= *********

now restart the server.


3)  Inside the portlet create a new file "ext-spring.xml" inside of "WEB-INF/src/META-INF" and paste the following content.

<?xml version="1.0"?>

<beans default-destroy-method="destroy" default-init-method="afterPropertiesSet"






       <bean id="customDataSource"


              <property name="targetDataSource">

                     <bean class="com.liferay.portal.dao.jdbc.util.DataSourceFactoryBean">

                           <property name="propertyPrefix" value="jdbc.custom.default." />





       <bean id="customHibernateSessionFactory"




                     value="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration" />



                           <entry key="dataSource" value-ref="customDataSource" />




       <bean id="customSessionFactory"




                     value="com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl" />



                           <entry key="dataSource" value-ref="customDataSource" />

                           <entry key="sessionFactoryClassLoader" value-ref="portletClassLoader" />

                           <entry key="sessionFactoryImplementor"

                                         value-ref="customHibernateSessionFactory" />





How to retrieve Informix data using Custom SQL statement ...?

Define a new entity 'CompanyExt' inside service.xml, mapped to informix data source and not the default one. table="company" & table="r_state" refers to the tables in Informix DB. The additional three attributes data-source, tx-manager and session-factory are mandatory. save file and generate the service layer.

Below is "service.xml" file entry.

<entity name="CompanyExt" local-service="true" remote-service="true"

              data-source="customDataSource" session-factory="customSessionFactory"  table="company">

              <column name="cmpy_id" type="int" primary="true" />

              <column name="reg_num" type="int" />

              <column name="company_name" type="String" />

              <column name="state" type="int" />



<entity name="State" local-service="true"  remote-service="true"

              data-source="customDataSource" session-factory="customSessionFactory"  table="r_state">

       <column name="state_code" type="int" primary="true"></column>

       <column name="state_desc" type="String"  ></column>


Create "default.xml" under "WEB-INF/src/custom-sql" (create the folder with the same name) and put the follwing custom SQL.

<?xml version="1.0" encoding="UTF-8"?>


              <sql id = "">


                     select * from company  where state=? ;




This file will have all the queries in simple SQL format in the form of key-value pairs. The key is the id that can be anything. The value is the actual query embedded within . If you look the value it is nothing but a simple SQL select statement.

Create a new finder implementation class “CompanyExtFinderImpl” inside “WEB- INF/src/com /slayer/service/persistence”. While creating this class make it implement “CompanyExtFinder” interface and extend “BasePersistenceImpl”.

Below is the '' file


public class CompanyExtFinderImpl extends BasePersistenceImpl implements CompanyExtFinder{

public static String FETCH_COMPANY_BY_STATE=CompanyExtFinderImpl.class.getName()+".fetchCompanyByState";


public List fetchCompanyByState(int state){

// 1. Open an ORM session Session session = openSession();

// 2. Get SQL statement from XML file with its name

String sql = CustomSQLUtil.get(FETCH_COMPANY_BY_STATE);

System.out.println("The Query is >>>>>>>>>"+sql);

// 3. Transform the normal query to HQL query

SQLQuery query = session.createSQLQuery(sql);

// 4. Add the actual entity to be searched

query.addEntity("CompanyExt", CompanyExtImpl.class);

// 5. Replace positional parameters in the query

QueryPos queryPos=QueryPos.getInstance(query);


// 6. Execute query and return results.

return (List<CompanyExt>query.list();




Make all the necessary imports required by the new code.

Update “CompanyExtLocalServiceImpl” with the below method to invoke our new custom finder.


public List fetchCompanyByState(int state) {

List companyExts=null;

companyExts = CompanyExtFinderUtil.fetchCompanyByState(state);

return companyExts;


Make the imports for LMSBookFinderUtil.

Below is the code in view.jsp to retrieve company details as per state code.


<%@page import="java.util.List"%>

<%@ taglib uri="" prefix="portlet"%>

<%@page import=""%>

<%@page import=""%>

<%@page import=""%>

<%@page import=""%>


List states=StateLocalServiceUtil.getStates(-1, -1);

for(State state:states){

List companyExts=CompanyExtLocalServiceUtil.fetchCompanyByState(state.getState_code());


for(CompanyExt companyExt:companyExts){ %>




<th>Company Id</th>

<th>Register Number</th>

<th>Company Name</th>









<%}}} %>

Once all done deploy the portlet and verify the result.