Fórumok

How to retrive the data from the database

anand gopalan, módosítva 11 év-val korábban

How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
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
thumbnail
Jignesh Vachhani, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Liferay Master Bejegyzések: 803 Csatlakozás dátuma: 2008.03.10. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
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
thumbnail
Harish Kumar, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 483 Csatlakozás dátuma: 2010.07.31. Legújabb bejegyzések
com.liferay.portal.model.User getUserByEmailAddress(long companyId, java.lang.String emailAddress)
anand gopalan, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
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
thumbnail
Jignesh Vachhani, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Liferay Master Bejegyzések: 803 Csatlakozás dátuma: 2008.03.10. Legújabb bejegyzések
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.
thumbnail
Harish Kumar, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 483 Csatlakozás dátuma: 2010.07.31. Legújabb bejegyzések
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-


User user = UserLocalServiceUtil.getUserByEmailAddress(companyId, emailAddress);
// call getters
String firstName = user.getFirstName(); 

you can get the companyId from themeDisplay object.


Regards
anand gopalan, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
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
thumbnail
Harish Kumar, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 483 Csatlakozás dátuma: 2010.07.31. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
Harish I am awating for your response.
thumbnail
Harish Kumar, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 483 Csatlakozás dátuma: 2010.07.31. Legújabb bejegyzések

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.


As per this you also want to have settters. Could you please explain the exact requirement?
anand gopalan, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
Harish, If you give the guideline today its really very very helpful for me.
anand gopalan, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
Hello Harish, Did u get any Ideas?
anand gopalan, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
any updates?
anand gopalan, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Expert Bejegyzések: 442 Csatlakozás dátuma: 2012.03.02. Legújabb bejegyzések
which class i need to import in JSP to get Firstname, lastname,............................

Please send your input.
thumbnail
Jignesh Vachhani, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Liferay Master Bejegyzések: 803 Csatlakozás dátuma: 2008.03.10. Legújabb bejegyzések
Harish Kumar:
com.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.
thumbnail
Gaurav Jain, módosítva 11 év-val korábban

RE: How to retrive the data from the database

Regular Member Bejegyzések: 145 Csatlakozás dátuma: 2011.01.31. Legújabb bejegyzések
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)