Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
How to retrive the data from the database anand gopalan October 3, 2012 5:45 AM
RE: How to retrive the data from the database Jignesh Vachhani October 3, 2012 5:59 AM
RE: How to retrive the data from the database anand gopalan October 5, 2012 2:41 AM
RE: How to retrive the data from the database Harish Kumar October 5, 2012 2:49 AM
RE: How to retrive the data from the database anand gopalan October 5, 2012 2:59 AM
RE: How to retrive the data from the database Jignesh Vachhani October 5, 2012 3:02 AM
RE: How to retrive the data from the database Harish Kumar October 5, 2012 3:05 AM
RE: How to retrive the data from the database anand gopalan October 5, 2012 4:02 AM
RE: How to retrive the data from the database Harish Kumar October 5, 2012 4:08 AM
RE: How to retrive the data from the database anand gopalan October 5, 2012 4:13 AM
RE: How to retrive the data from the database anand gopalan October 5, 2012 4:16 AM
RE: How to retrive the data from the database anand gopalan October 5, 2012 4:26 AM
RE: How to retrive the data from the database Harish Kumar October 5, 2012 4:36 AM
RE: How to retrive the data from the database anand gopalan October 5, 2012 4:57 AM
RE: How to retrive the data from the database anand gopalan October 5, 2012 5:08 AM
RE: How to retrive the data from the database anand gopalan October 5, 2012 5:49 AM
RE: How to retrive the data from the database anand gopalan October 8, 2012 1:48 AM
RE: How to retrive the data from the database anand gopalan October 8, 2012 2:16 AM
RE: How to retrive the data from the database anand gopalan October 8, 2012 5:18 AM
RE: How to retrive the data from the database anand gopalan October 8, 2012 5:33 AM
RE: How to retrive the data from the database Jignesh Vachhani October 5, 2012 3:00 AM
RE: How to retrive the data from the database Gaurav Jain October 5, 2012 3:05 AM
anand gopalan
How to retrive the data from the database
October 3, 2012 5:45 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

Hi,
How to retrive the data from the User_ table.

Enviornment:
Database: MySQL5.5
Liferay - IDE - Ecplise
Liferay6.1.0

Field Name:

UserId, firstname, lastname,middlename,screenname emailaddress

Condition: select userID,firstname,lastname,middlename,screenname,emailaddress from user_ where emailaddress="test@liferay.com";

User id is Primary Key.

Please let me how to do with service.xml or any other way. Please give me suggestion or code.

Regards
Anand
Jignesh Vachhani
RE: How to retrive the data from the database
October 3, 2012 5:59 AM
Answer

Jignesh Vachhani

Rank: Liferay Master

Posts: 780

Join Date: March 10, 2008

Recent Posts

Use Dyamic query concept here to retrive data as per your query.
You can see details about dynamic query on below links :
http://www.liferay.com/community/forums/-/blogs/3813353/maximized
http://www.liferay.com/community/wiki/-/wiki/1071674/Dynamic+Query+API/maximized
anand gopalan
RE: How to retrive the data from the database
October 5, 2012 2:41 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

Hi Jignesh,

do you have any example to use dyanmic query, I found some examples in Liferay Forum, But all are
store the data from the form and display.

But requirement is I don't store the data from the Form, Already I have table I want to fetch the record and display in view.jsp

For example: User_ table in MySql, I want to get the record and display in view.jsp.

Please help.

Regards
Anand
Harish Kumar
RE: How to retrive the data from the database
October 5, 2012 2:49 AM
Answer

Harish Kumar

Rank: Expert

Posts: 336

Join Date: July 31, 2010

Recent Posts

1com.liferay.portal.model.User getUserByEmailAddress(long companyId, java.lang.String emailAddress)
anand gopalan
RE: How to retrive the data from the database
October 5, 2012 2:59 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

Hello Harish,
where to write the above code, I didn't create any java code.
I created only view.jsp.

Please give me the step to achieve my task.

Please give ur guideance
Regards
Anand
Jignesh Vachhani
RE: How to retrive the data from the database
October 5, 2012 3:00 AM
Answer

Jignesh Vachhani

Rank: Liferay Master

Posts: 780

Join Date: March 10, 2008

Recent Posts

Harish Kumar:
1com.liferay.portal.model.User getUserByEmailAddress(long companyId, java.lang.String emailAddress)


Perfect solutions Harish
Anand , you can directly use the API suggested by Harish as its already available.
Jignesh Vachhani
RE: How to retrive the data from the database
October 5, 2012 3:02 AM
Answer

Jignesh Vachhani

Rank: Liferay Master

Posts: 780

Join Date: March 10, 2008

Recent Posts

Anand,

You can use scriptlet in your jsp and the method which Harish suggested will return user object and from that user object you can get all metadata of user.
Gaurav Jain
RE: How to retrive the data from the database
October 5, 2012 3:05 AM
Answer

Gaurav Jain

Rank: Regular Member

Posts: 141

Join Date: January 31, 2011

Recent Posts

There are various methods in UserLocalServiceUtil.

Import this class in your jsp/java file and call the methods you would like :
- byEmail : com.liferay.portal.service.UserLocalServiceUtil.getUserByEmailAddress(long companyId, String emailAddress)
- byScreenName : com.liferay.portal.service.UserLocalServiceUtil.getUserByScreenName(long companyId, String screenName)
- byId : com.liferay.portal.service.UserLocalServiceUtil.getUser(long userId)

You can get companyId by themeDisplay object or by PortalUtil method:
com.liferay.portal.util.PortalUtil.getCompanyId(HttpServletRequest request)
Harish Kumar
RE: How to retrive the data from the database
October 5, 2012 3:05 AM
Answer

Harish Kumar

Rank: Expert

Posts: 336

Join Date: July 31, 2010

Recent Posts

anand gopalan:
Hello Harish,
where to write the above code, I didn't create any java code.
I created only view.jsp.

Please give me the step to achieve my task.

Please give ur guideance
Regards
Anand


Here is sample code-

1
2User user = UserLocalServiceUtil.getUserByEmailAddress(companyId, emailAddress);
3// call getters
4String firstName = user.getFirstName();
5
6you can get the companyId from themeDisplay object.


Regards
anand gopalan
RE: How to retrive the data from the database
October 5, 2012 4:02 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

Thank you so much Harish, for your code and I achieved that.

But things is User_ table is the Liferay table. so there will be set method will be defined but I created the employee table

now I want to fetch the record based on some condition. where I can write my set method & get method. give me the folder structure how to implement.

Please send your guideline. So will very very helpful. I new bee for Liferay.

regards
Anand
Harish Kumar
RE: How to retrive the data from the database
October 5, 2012 4:08 AM
Answer

Harish Kumar

Rank: Expert

Posts: 336

Join Date: July 31, 2010

Recent Posts

How did you created the employee table.

If you want to develop your custom entity, you can make use of service builder. Its a code generation tool provided by Liferay.

You can find details of service builder with example here

Regards
anand gopalan
RE: How to retrive the data from the database
October 5, 2012 4:13 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

Directly create and insert in mysql database.
can I use any condition like
select firstname,lastname,empId,emailaddress from User_ where firstname='karthik';

please........ reply.
anand gopalan
RE: How to retrive the data from the database
October 5, 2012 4:16 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

Harish I saw the example but that is create & retrive the data via service builder but I want only retrive by custom entity.
anand gopalan
RE: How to retrive the data from the database
October 5, 2012 4:26 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

Harish I am awating for your response.
Harish Kumar
RE: How to retrive the data from the database
October 5, 2012 4:36 AM
Answer

Harish Kumar

Rank: Expert

Posts: 336

Join Date: July 31, 2010

Recent Posts

1
2now I want to fetch the record based on some condition. where I can write my set method & get method. give me the folder structure how to implement.


As per this you also want to have settters. Could you please explain the exact requirement?
anand gopalan
RE: How to retrive the data from the database
October 5, 2012 4:57 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

My Requirement

My Own Table Name: Employee
Database: Mysql

Field Name:

empId - Primary Key
employeeName
casualLeave
seekLeave
paidLeave

Query condition:
Select employeename,empId,casualLeave,seekleave,paidLeave from employee where empId='1010316';

I want display the result in View.jsp

Please help how to achieve this.
anand gopalan
RE: How to retrive the data from the database
October 5, 2012 5:08 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

Harish, If you give the guideline today its really very very helpful for me.
anand gopalan
RE: How to retrive the data from the database
October 5, 2012 5:49 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

Hello Harish, Did u get any Ideas?
anand gopalan
RE: How to retrive the data from the database
October 8, 2012 1:48 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

any updates?
anand gopalan
RE: How to retrive the data from the database
October 8, 2012 2:16 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

I created a new Portlet to display the data,

now I stuck up in, what to define in service.xml for retrival data. Please send your suggestion & help.
anand gopalan
RE: How to retrive the data from the database
October 8, 2012 5:18 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

I define below code in service.xml and build the service.xml

<entity name="lportal" local-service="true" table="employee"
remote-service="true" data-source="myDatasource">
<column name="empId" type="long" primary="true"></column>
<column name="employeeName" type="String"></column>
<column name="casualLeave" type="long"></column>
<column name="seekLeave" type="long"></column>
<column name="paidLeave" type="long"></column>

</entity>

now please tell me how to display the employee details in view.jsp
anand gopalan
RE: How to retrive the data from the database
October 8, 2012 5:33 AM
Answer

anand gopalan

Rank: Expert

Posts: 403

Join Date: March 2, 2012

Recent Posts

which class i need to import in JSP to get Firstname, lastname,............................

Please send your input.