Foren
retrieving data from mysql
deb chakraverty, geändert vor 12 Jahren.
retrieving data from mysql
Regular Member Beiträge: 161 Beitrittsdatum: 07.02.12 Neueste Beiträge
Hi all,
I already connected mysql with liferay 6.0. Can any body please tell me in depth that, how to retrieve data from mysql database to liferay 6.0. I am a newbie in liferay so i need some depth information.
I already connected mysql with liferay 6.0. Can any body please tell me in depth that, how to retrieve data from mysql database to liferay 6.0. I am a newbie in liferay so i need some depth information.
Juhi Kumari, geändert vor 12 Jahren.
RE: retrieving data from mysql
Expert Beiträge: 347 Beitrittsdatum: 12.12.11 Neueste Beiträge
Hi deb,
If you want to retrieve all records from a table, suppose you want to retrieve all records from user_ table then use
Or any particular records you can use
Regards
Juhi
If you want to retrieve all records from a table, suppose you want to retrieve all records from user_ table then use
List<user> userList = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount());</user>
Or any particular records you can use
User user = UserLocalServiceUtil.getUser(userId);
depends on your requirement.Regards
Juhi
dev ch, geändert vor 12 Jahren.
RE: retrieving data from mysql
Regular Member Beiträge: 161 Beitrittsdatum: 07.02.12 Neueste Beiträge
thank you..
David H Nebinger, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste BeiträgeJuhi Kumari:
UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount());
This is wrong and results in an extra database call.
Use
UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
instead.
Priyanka Dhingra, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Master Beiträge: 501 Beitrittsdatum: 20.12.11 Neueste Beiträge
I used
and liferay ui:search container for displaying the records.
Regards
Priyanka
List<Employee> empList = new ArrayList<Employee>();
empList = EmployeeLocalServiceUtil.findAll();
and liferay ui:search container for displaying the records.
Regards
Priyanka
dev ch, geändert vor 12 Jahren.
RE: retrieving data from mysql
Regular Member Beiträge: 161 Beitrittsdatum: 07.02.12 Neueste Beiträge
Thank you Priyanka..
RathnaDevi Chellaiah, geändert vor 12 Jahren.
RE: retrieving data from mysql
Junior Member Beiträge: 29 Beitrittsdatum: 27.03.12 Neueste Beiträge
Hi Priyanka,
Can u tell me how to retrieve data using servicebuilder created in one portlet to another portlet.? i already created a portlet with service builder to insert data into database thereafter created another portlet and copied the firs portlet's jar(WEB-INF/lib) to the new one's lib.. still its not working ? after searching some forum, i copied the jar to tomcat's lib..Even that doesn't work.... Is there any solution??????? am using liferay-plugins-sdk-6.0.6-20110225 and liferay-portal-6.0.6 tomcat for my application.
Thanks in advance.
Can u tell me how to retrieve data using servicebuilder created in one portlet to another portlet.? i already created a portlet with service builder to insert data into database thereafter created another portlet and copied the firs portlet's jar(WEB-INF/lib) to the new one's lib.. still its not working ? after searching some forum, i copied the jar to tomcat's lib..Even that doesn't work.... Is there any solution??????? am using liferay-plugins-sdk-6.0.6-20110225 and liferay-portal-6.0.6 tomcat for my application.
Thanks in advance.
Jitendra Rajput, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Master Beiträge: 875 Beitrittsdatum: 07.01.11 Neueste Beiträge
Rathna ,
If i am not wrong then you want to share your services between plugin portlets.
You can do it via two ways ..
1)
You created a service for producer portlet named producer-service.jar .
Now remove this jar from your portlet/WEB-INF/lib and if its placed inside any other location remove from thr also .
and place inside tomcat/lib/ext
restart your server . Now you can easily access produce service jar inside any other portlet as its placed inside global class path
2) Copy your produce-service.jar and place inside portlet's WEB - INF / lib which want to access this services.
make sure your produce portlet is deployed other wise you might rcv beanlocator is null kind of exception
look into below wiki for more info
http://www.liferay.com/community/wiki/-/wiki/Main/Using+Class+Loader+Proxy+classes+to+share+plugins+services
If i am not wrong then you want to share your services between plugin portlets.
You can do it via two ways ..
1)
You created a service for producer portlet named producer-service.jar .
Now remove this jar from your portlet/WEB-INF/lib and if its placed inside any other location remove from thr also .
and place inside tomcat/lib/ext
restart your server . Now you can easily access produce service jar inside any other portlet as its placed inside global class path
2) Copy your produce-service.jar and place inside portlet's WEB - INF / lib which want to access this services.
make sure your produce portlet is deployed other wise you might rcv beanlocator is null kind of exception
look into below wiki for more info
http://www.liferay.com/community/wiki/-/wiki/Main/Using+Class+Loader+Proxy+classes+to+share+plugins+services
David H Nebinger, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste BeiträgeJitendra Rajput:
Rathna ,
If i am not wrong then you want to share your services between plugin portlets.
You can do it via two ways ..
1)
You created a service for producer portlet named producer-service.jar .
Now remove this jar from your portlet/WEB-INF/lib and if its placed inside any other location remove from thr also .
and place inside tomcat/lib/ext
restart your server . Now you can easily access produce service jar inside any other portlet as its placed inside global class path
2) Copy your produce-service.jar and place inside portlet's WEB - INF / lib which want to access this services.
make sure your produce portlet is deployed other wise you might rcv beanlocator is null kind of exception
look into below wiki for more info
http://www.liferay.com/community/wiki/-/wiki/Main/Using+Class+Loader+Proxy+classes+to+share+plugins+services
This is also wrong. Add the producer-portlet as a required deployment context for the subscriber portlet. The service jar will automatically be included. Do not manually remove and/or copy jars around on your own.
Priyanka Dhingra, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Master Beiträge: 501 Beitrittsdatum: 20.12.11 Neueste Beiträge
hi RathnaDevi Chellaiah,
You can create 2 portlets in one liferay portlet project. and as per your requirement use Inter Portlet Communication(IPC). You'll be able to achieve what you wanna do
Regards
Priyanka
You can create 2 portlets in one liferay portlet project. and as per your requirement use Inter Portlet Communication(IPC). You'll be able to achieve what you wanna do
Regards
Priyanka
RathnaDevi Chellaiah, geändert vor 12 Jahren.
RE: retrieving data from mysql
Junior Member Beiträge: 29 Beitrittsdatum: 27.03.12 Neueste Beiträge
hi,
Thanks a lot.. it worked well. i have another problem.. i have created and deployed a registration form say employee details in a portlet where i used service builder to store in lportal db. it stored successfully. my problem is- based on the registration form i need to create a login for the employee who have registered. this login should be integrated with liferay user login as shown in the attached pic and it should create a user account page for the particular user in liferay...? how to implement this...??????
Thanks a lot.. it worked well. i have another problem.. i have created and deployed a registration form say employee details in a portlet where i used service builder to store in lportal db. it stored successfully. my problem is- based on the registration form i need to create a login for the employee who have registered. this login should be integrated with liferay user login as shown in the attached pic and it should create a user account page for the particular user in liferay...? how to implement this...??????
Anhänge:
Jitendra Rajput, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Master Beiträge: 875 Beitrittsdatum: 07.01.11 Neueste Beiträge
You should create different thread for different question.
and regarding your question .
When even you are saving employee details at the same time if you have complete user information then you can save inside user_ table.
Using UserLocalServiceUtil.addUser() you can add new user in Liferay database.
Once user is added they can access your system.
and regarding your question .
When even you are saving employee details at the same time if you have complete user information then you can save inside user_ table.
Using UserLocalServiceUtil.addUser() you can add new user in Liferay database.
Once user is added they can access your system.
RathnaDevi Chellaiah, geändert vor 12 Jahren.
RE: retrieving data from mysql
Junior Member Beiträge: 29 Beitrittsdatum: 27.03.12 Neueste Beiträge
k. i did as u said still user not created in liferay.. can u send me a sample appli based on it..?
RathnaDevi Chellaiah, geändert vor 12 Jahren.
RE: retrieving data from mysql
Junior Member Beiträge: 29 Beitrittsdatum: 27.03.12 Neueste Beiträge
RathnaDevi Chellaiah, geändert vor 12 Jahren.
RE: retrieving data from mysql
Junior Member Beiträge: 29 Beitrittsdatum: 27.03.12 Neueste Beiträge
hi priyanka
i need ur help....am facing an issue regarding the creation of user using user form data.. my scenario is i have to create a registration form that is used by service builder and based on that it stores the value into db(lportel).. at the same time the value in the form should create a user into the liferay user table.
i have achieved upto storing of db.. but facing issue with creating user.. the form data is not fetched and stored into the predefined attributes of userlocalservice..
public void processAction(ActionRequest request,ActionResponse response) {
try {
long userId=CounterLocalServiceUtil.increment();
User user=UserLocalServiceUtil.createUser(userId);
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
long creatorId=0;
long companyId = themeDisplay.getCompanyId();
user.setCompanyId(companyId);
boolean autoPassword = true;
String password1 = "";
user.setPassword(password1);
String password2 = "";
user.setPassword(password2);
boolean autoScreenName = true;
String screenName = "MyProfile1";
user.setScreenName(screenName);
String compemail = request.getParameter("cemail");// from the view.jsp page
user.setEmailAddress(compemail);
long facebookId = 0;
user.setFacebookId(facebookId);
String openId = "";
user.setOpenId(openId);
// Locale locale = themeDisplay.getLocale();
String firstName = request.getParameter("fname");// from the view.jsp page
user.setActive(true);
user.setFirstName(firstName);
String middleName = "";
String lastName = request.getParameter("lname");// from the view.jsp page
user.setLastName(lastName);
int prefixId = 0;
int suffixId = 0;
boolean male = true;
int birthdayMonth = 0;
int birthdayDay = 0;
int birthdayYear = 0;
String designation =request.getParameter("designation");// from the view.jsp page
user.setJobTitle(designation);
long[] groupIds = null;
long[] organizationIds = null;
long[] roleIds = null;
long[] userGroupIds = null;
boolean sendEmail = true;
com.liferay.portal.service.ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), request);
UserLocalServiceUtil.addUser(creatorId,
themeDisplay.getCompanyId(), autoPassword, password1, password2,
autoScreenName, screenName, compemail, facebookId, openId,
LocaleUtil.getDefault(), firstName, middleName, lastName, prefixId,
suffixId, male, birthdayMonth, birthdayDay, birthdayYear, designation,
groupIds, organizationIds, roleIds, userGroupIds, sendEmail,
serviceContext);
}
catch(Exception e){
e.printStackTrace();
}
}
i have tried many code posted in forum but nothing worked.......... please give me guide on this issue..
i need ur help....am facing an issue regarding the creation of user using user form data.. my scenario is i have to create a registration form that is used by service builder and based on that it stores the value into db(lportel).. at the same time the value in the form should create a user into the liferay user table.
i have achieved upto storing of db.. but facing issue with creating user.. the form data is not fetched and stored into the predefined attributes of userlocalservice..
public void processAction(ActionRequest request,ActionResponse response) {
try {
long userId=CounterLocalServiceUtil.increment();
User user=UserLocalServiceUtil.createUser(userId);
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
long creatorId=0;
long companyId = themeDisplay.getCompanyId();
user.setCompanyId(companyId);
boolean autoPassword = true;
String password1 = "";
user.setPassword(password1);
String password2 = "";
user.setPassword(password2);
boolean autoScreenName = true;
String screenName = "MyProfile1";
user.setScreenName(screenName);
String compemail = request.getParameter("cemail");// from the view.jsp page
user.setEmailAddress(compemail);
long facebookId = 0;
user.setFacebookId(facebookId);
String openId = "";
user.setOpenId(openId);
// Locale locale = themeDisplay.getLocale();
String firstName = request.getParameter("fname");// from the view.jsp page
user.setActive(true);
user.setFirstName(firstName);
String middleName = "";
String lastName = request.getParameter("lname");// from the view.jsp page
user.setLastName(lastName);
int prefixId = 0;
int suffixId = 0;
boolean male = true;
int birthdayMonth = 0;
int birthdayDay = 0;
int birthdayYear = 0;
String designation =request.getParameter("designation");// from the view.jsp page
user.setJobTitle(designation);
long[] groupIds = null;
long[] organizationIds = null;
long[] roleIds = null;
long[] userGroupIds = null;
boolean sendEmail = true;
com.liferay.portal.service.ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), request);
UserLocalServiceUtil.addUser(creatorId,
themeDisplay.getCompanyId(), autoPassword, password1, password2,
autoScreenName, screenName, compemail, facebookId, openId,
LocaleUtil.getDefault(), firstName, middleName, lastName, prefixId,
suffixId, male, birthdayMonth, birthdayDay, birthdayYear, designation,
groupIds, organizationIds, roleIds, userGroupIds, sendEmail,
serviceContext);
}
catch(Exception e){
e.printStackTrace();
}
}
i have tried many code posted in forum but nothing worked.......... please give me guide on this issue..
David H Nebinger, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste BeiträgeRathnaDevi Chellaiah:
i have tried many code posted in forum but nothing worked.......... please give me guide on this issue..
Many of the solutions in the forum, while incomplete, will work. Do you have any exceptions spit out from the try/catch block? How do you define "nothing worked"? User is not in the users list (did you try reindexing), or what?
RathnaDevi Chellaiah, geändert vor 12 Jahren.
RE: retrieving data from mysql
Junior Member Beiträge: 29 Beitrittsdatum: 27.03.12 Neueste Beiträge
hi
ya i tried using reindexing too.. my exception is null pointer exception.. it doesn't take value from view.jsp ...
ya i tried using reindexing too.. my exception is null pointer exception.. it doesn't take value from view.jsp ...
David H Nebinger, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
Then that is a completely different issue than the "nothing worked" thing that you said before...
RathnaDevi Chellaiah, geändert vor 12 Jahren.
RE: retrieving data from mysql
Junior Member Beiträge: 29 Beitrittsdatum: 27.03.12 Neueste Beiträge
k is this the right way to take data from html form and put in to the parameter of addUser??????? if yes,why doesn't it takes the value from form data and assign...?????
String compemail = request.getParameter("cemail");
String compemail = request.getParameter("cemail");
Jitendra Rajput, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Master Beiträge: 875 Beitrittsdatum: 07.01.11 Neueste Beiträge
Any error in log ?
Hitoshi Ozawa, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträgeya i tried using reindexing too.. my exception is null pointer exception.. it doesn't take value from view.jsp ...
He's saying he's getting null exception. I think it's because he've set organization to null and I thought that was a required field. Unfortunately, Liferay API documentation doesn't specify which fields are required and this problem has come up often. I think every developer has encountered it once.
Ravi Kumar Gupta, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
It should not happen.. you should be getting values properly.. just check if u r using right names for parameters...
Also, if you can attach the latest portlet code.. that would help us understanding more..
-Ravi
Also, if you can attach the latest portlet code.. that would help us understanding more..
-Ravi
Priyanka Dhingra, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Master Beiträge: 501 Beitrittsdatum: 20.12.11 Neueste BeiträgeRathnaDevi Chellaiah:
k is this the right way to take data from html form and put in to the parameter of addUser??????? if yes,why doesn't it takes the value from form data and assign...?????
String compemail = request.getParameter("cemail");
It does work....this is to be done in your processAction() method...
RathnaDevi Chellaiah, geändert vor 12 Jahren.
RE: retrieving data from mysql
Junior Member Beiträge: 29 Beitrittsdatum: 27.03.12 Neueste Beiträge
hi,
It worked.. thank u for ur reply. Now am able to create user in the user_ table of liferay but mail is not shot to the created user? what to do?
It worked.. thank u for ur reply. Now am able to create user in the user_ table of liferay but mail is not shot to the created user? what to do?
Hitoshi Ozawa, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträgelong[] organizationIds = null;
Have you tried specifying an organization.
RathnaDevi Chellaiah, geändert vor 12 Jahren.
RE: retrieving data from mysql
Junior Member Beiträge: 29 Beitrittsdatum: 27.03.12 Neueste Beiträge
ya u r right.. i have kept long[] organizationIds = null;
what should i replace instead of null.. please tell me..
what should i replace instead of null.. please tell me..
MICHAIL MOUDATSOS, geändert vor 12 Jahren.
RE: retrieving data from mysql
Regular Member Beiträge: 110 Beitrittsdatum: 04.10.11 Neueste Beiträgelong[] organizationIds = new long[]{};
RathnaDevi Chellaiah, geändert vor 12 Jahren.
RE: retrieving data from mysql
Junior Member Beiträge: 29 Beitrittsdatum: 27.03.12 Neueste Beiträge
thank u MICHAIL, even though its not working...
Jitendra Rajput, geändert vor 12 Jahren.
RE: retrieving data from mysql
Liferay Master Beiträge: 875 Beitrittsdatum: 07.01.11 Neueste Beiträgeit doesn't take value from view.jsp
You mean to say you are not able to retrieve form values from request ?.
If so then check enctype attribute of form .. If you are using multipart/form-data in enctype then try to retrieve form values from UploadRequest.
Joel Peterson, geändert vor 12 Jahren.
RE: retrieving data from mysql
New Member Beiträge: 22 Beitrittsdatum: 18.02.10 Neueste BeiträgeRathnaDevi Chellaiah:
hi
ya i tried using reindexing too.. my exception is null pointer exception.. it doesn't take value from view.jsp ...
In your view.jsp, are you prefacing your form inputs' name attributes with the portlet namespace? If so, then you should probably use Liferay's ParamUtil method to retrieve the form values in your processAction method.
<input name="<portlet:namespace/>myInputName" type="text">
String myInputValue = com.liferay.portal.kernel.util.ParamUtil.getString(request,"myInputName","my default value");
RathnaDevi Chellaiah, geändert vor 12 Jahren.
RE: retrieving data from mysql
Junior Member Beiträge: 29 Beitrittsdatum: 27.03.12 Neueste Beiträge
No. see the following view.jsp of mine
<html>
<head>
</head>
<body>
<form action='<portlet:actionURL/>' method="post">
<table cellpadding="20" cellspacing="20"> <tr>
<td><label>First Name</label><sup>*</sup></td>
<td> <input type="text" name="fname"></td> </tr>
<tr>
<td><label>Last Name</label><sup>*</sup></td>
<td><input type="text" name="lname"></td>
</tr>
<tr><td><label>Company Email-ID</label><sup>*</sup></td>
<td><input type="text" name="cemailid"></td></tr>
<tr><td><label>Password</label><sup>*</sup></td>
<td><input type="text" name="password1"></td></tr>
<tr><td><label>Confirm Password </label><sup>*</sup></td>
<td><input type="text" name="password2"></td></tr>
<tr><td><input type="submit" value="Submit"></td>
<td><input type="Reset"></td></tr>
</table>
</form>
</body>
</html>
<html>
<head>
</head>
<body>
<form action='<portlet:actionURL/>' method="post">
<table cellpadding="20" cellspacing="20"> <tr>
<td><label>First Name</label><sup>*</sup></td>
<td> <input type="text" name="fname"></td> </tr>
<tr>
<td><label>Last Name</label><sup>*</sup></td>
<td><input type="text" name="lname"></td>
</tr>
<tr><td><label>Company Email-ID</label><sup>*</sup></td>
<td><input type="text" name="cemailid"></td></tr>
<tr><td><label>Password</label><sup>*</sup></td>
<td><input type="text" name="password1"></td></tr>
<tr><td><label>Confirm Password </label><sup>*</sup></td>
<td><input type="text" name="password2"></td></tr>
<tr><td><input type="submit" value="Submit"></td>
<td><input type="Reset"></td></tr>
</table>
</form>
</body>
</html>
Kalpesh Sangani, geändert vor 12 Jahren.
RE: retrieving data from mysql
New Member Beiträge: 4 Beitrittsdatum: 22.11.11 Neueste Beiträge
Through DynamicQuery you can also retrieve data if you have some special condition as below
DynamicQuery query = DynamicQueryFactoryUtil.forClass(ContactUs.class, PortletClassLoaderUtil.getClassLoader())
.add(PropertyFactoryUtil.forName("contactId").eq(new Long("3")))
.addOrder(OrderFactoryUtil.asc("contactId"));
List <ContactUs>results = ContactUsLocalServiceUtil.dynamicQuery(query, -1, -1);
DynamicQuery query = DynamicQueryFactoryUtil.forClass(ContactUs.class, PortletClassLoaderUtil.getClassLoader())
.add(PropertyFactoryUtil.forName("contactId").eq(new Long("3")))
.addOrder(OrderFactoryUtil.asc("contactId"));
List <ContactUs>results = ContactUsLocalServiceUtil.dynamicQuery(query, -1, -1);