Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Bakhtawar Khan
Retrieving data from database
August 18, 2012 3:07 AM
Answer

Bakhtawar Khan

Rank: New Member

Posts: 14

Join Date: August 5, 2012

Recent Posts

hiee All,
I want to retrieve data from database and display it on my portlet.Can someone tell me how to do that???emoticon
devaraj s
RE: Retrieving data from database
August 18, 2012 3:21 AM
Answer

devaraj s

Rank: Regular Member

Posts: 216

Join Date: May 21, 2012

Recent Posts

Bakhtawar Khan:
hiee All,
I want to retrieve data from database and display it on my portlet.Can someone tell me how to do that???emoticon



which databse you using for liferay.. Liferay by default will run on hsql database.. If you want to you can change to mysql or whichever database compaiatble to you..

Suppose you using mysql database means you create service.xml file by defining your db entities. once it done you build a service.

from persistance object you can add or retrieve the data from database.

xxxLocalServiceUtil Class and use there respective functions to get appropriate data.
Bakhtawar Khan
RE: Retrieving data from database
August 18, 2012 4:02 AM
Answer

Bakhtawar Khan

Rank: New Member

Posts: 14

Join Date: August 5, 2012

Recent Posts

I am using mysql.I am already done with building service but i am not getting the desired db on my portlet.
Hitoshi Ozawa
RE: Retrieving data from database
August 18, 2012 4:16 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

When you build your service there should have been xxxxLocalServiceUtil class generated. ( where xxx is hte name of your entity).

You just have to do a get() on the column you've defined.

How are you trying to display the data?
Bakhtawar Khan
RE: Retrieving data from database
August 18, 2012 4:31 AM
Answer

Bakhtawar Khan

Rank: New Member

Posts: 14

Join Date: August 5, 2012

Recent Posts

I have already done that....now i just want to display the content on another portlet.Any idea how to do that??emoticon
devaraj s
RE: Retrieving data from database
August 18, 2012 4:40 AM
Answer

devaraj s

Rank: Regular Member

Posts: 216

Join Date: May 21, 2012

Recent Posts

Bakhtawar Khan:
I have already done that....now i just want to display the content on another portlet.Any idea how to do that??emoticon



I think you have to use inetportlet communication concept.. Please correct me if this suggestion wrong ..
Bakhtawar Khan
RE: Retrieving data from database
August 18, 2012 5:00 AM
Answer

Bakhtawar Khan

Rank: New Member

Posts: 14

Join Date: August 5, 2012

Recent Posts

ya.....I am new to liferay so it will be better if u provide me steps to do that.
Rewati Raman
RE: Retrieving data from database
August 18, 2012 6:16 AM
Answer

Rewati Raman

Rank: Junior Member

Posts: 97

Join Date: February 24, 2012

Recent Posts

Bakhtawar Khan:
ya.....I am new to liferay so it will be better if u provide me steps to do that.





just take the jar from the lib of the portlet on which you had created the service.xml and paste it in the liferay-portal/tomcat/lib/ext then
write the following lines in your view.jsp page
here XXX means your entity Name Defined in service.xml

 1
 2<%
 3int count = XXXLocalServiceUtil.getXXXsCount();
 4List<XXX> resultList = XXXLocalServiceUtil.getXXXs(0, count);
 5%>
 6
 7<table border="1" width="80%">
 8<tr>
 9<th>ID</th>
10<th>Name Of Canadidate </th>
11<th>Phone</th>
12<th>DOB</th>
13
14</tr>
15<%
16for (XXX res : resultList) {
17%>
18<tr>
19<td><%= res.getId() %></td>
20<td><%= res.getName() %></td>
21<td><%= res.getPhone() %></td>
22<td><%= res.getDob() %></td>
23</tr>
24
25<%
26}
27%>
28</table>



the above code will retreive the data
in the tablular format

it works for me every time

Regards,
Rewati Raman
devaraj s
RE: Retrieving data from database
August 18, 2012 11:16 AM
Answer

devaraj s

Rank: Regular Member

Posts: 216

Join Date: May 21, 2012

Recent Posts

Bakhtawar Khan:
ya.....I am new to liferay so it will be better if u provide me steps to do that.



refer this article you ill get an idea about IPC.

http://www.liferay.com/community/wiki/-/wiki/Main/Portlet+to+Portlet+Communication
Sagar A Vyas
RE: Retrieving data from database
August 18, 2012 11:30 AM
Answer

Sagar A Vyas

Rank: Liferay Master

Posts: 657

Join Date: April 17, 2009

Recent Posts

Bakhtawar Khan:
hiee All,
I want to retrieve data from database and display it on my portlet.Can someone tell me how to do that???emoticon


Hi Bakhtawar,

Please refer this
http://www.liferay.com/web/guest/community/forums/-/message_boards/view_message/15700837
.

Thanks,
Sagar Vyas