掲示板

retrive data from database

thumbnail
12年前 に Abid Ali によって更新されました。

retrive data from database

Junior Member 投稿: 88 参加年月日: 12/03/31 最新の投稿
hi,
I successfully stored datas in database(mysql) using liferay,
now i want to retrive data using primerykey from mysql.
how i will do it
thumbnail
12年前 に David H Nebinger によって更新されました。

RE: retrive data from database

Liferay Legend 投稿: 14917 参加年月日: 06/09/02 最新の投稿
Hmm, there's jdbc, a little higher up from that is Hibernate, and if you're doing things the Liferay way then you've been using ServiceBuilder and the methods already exist.
thumbnail
12年前 に Abid Ali によって更新されました。

RE: retrive data from database

Junior Member 投稿: 88 参加年月日: 12/03/31 最新の投稿
can u tell me elaborately. how i will write in service builder
thumbnail
12年前 に Ravi Kumar Gupta によって更新されました。

RE: retrive data from database

Liferay Legend 投稿: 1302 参加年月日: 09/06/24 最新の投稿
thumbnail
12年前 に Abid Ali によって更新されました。

RE: retrive data from database

Junior Member 投稿: 88 参加年月日: 12/03/31 最新の投稿
Ravi,
u gave example for store the data in database. but stored successfully using persistence Api. but i want to retrive data using primarykey.
i want to know how ?
thumbnail
12年前 に Priyanka Dhingra によって更新されました。

RE: retrive data from database

Liferay Master 投稿: 501 参加年月日: 11/12/20 最新の投稿
Hi Abid,
You want to fetch all the data through primary key or you want it to be like, you enter some primary key and then u get that particular data???

Anyhow I used <finder> in service.xml to fetch the content and display in portlet

try: http://www.liferay.com/community/wiki/-/wiki/Main/Finder+tags+in+service.xml
thumbnail
12年前 に Abid Ali によって更新されました。

RE: retrive data from database

Junior Member 投稿: 88 参加年月日: 12/03/31 最新の投稿
its difficult to understand. please easy way to under stand.
thumbnail
12年前 に Ravi Kumar Gupta によって更新されました。

RE: retrive data from database

Liferay Legend 投稿: 1302 参加年月日: 09/06/24 最新の投稿
Abid,

If you are using service builder, then you can get data from XXXLocalServiceUtil.java or XXXServiceUtil.java(this will need permission check as well). I hope you understand this one.

If you are not using service builder, I would suggest-start using. Anyways.. the way you have inserted data to database, the same persistence api won't provide methods to retrieve data?

I am kind of not getting you here properly, can you please share the code/portlet here.
thumbnail
12年前 に Abid Ali によって更新されました。

RE: retrive data from database

Junior Member 投稿: 88 参加年月日: 12/03/31 最新の投稿
here I develop code for storing data in database from portal.
1.view.jsp
---------------

<%@page import="javax.portlet.PortletContext"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>


<portlet:actionURL name="" var="actionUrl"></portlet:actionURL>


<aui:layout>
<aui:form name="fm" action="<%=actionUrl.toString() %>" method="post">
<aui:column>
<aui:input name="id" type="text"></aui:input>
<aui:input name="name" type="text"></aui:input>
<aui:input name="phone" type="text"></aui:input>
<aui:button value="submit" type="submit"></aui:button>
</aui:column>

</aui:form>
</aui:layout>


2.Service.xml
-------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
<service-builder package-path="com.test">
<author>sourceone</author>
<namespace>Abid</namespace>

<entity name="Table1" local-service="true" remote-service="false" >

<!-- PK fields -->

<!-- Audit fields -->

<!-- Other fields -->

<!-- Order -->
<column name="id" primary="true" type="long"></column>
<column name="Name" type="String"></column>
<column name="Phone" type="long"></column>


</entity>
</service-builder>
3.InsertData.java(which is extends MVCPortlet)
----------------------------------------------------------------
package com.test;



import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import com.sun.xml.internal.bind.v2.runtime.Name;
import com.test.model.impl.*;
import com.test.service.*;

import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
import com.liferay.util.bridges.mvc.MVCPortlet;

/**
* Portlet implementation class InsertData
*/
public class InsertData extends MVCPortlet {


public void processAction(ActionRequest request,ActionResponse response)
{

long id =ParamUtil.getLong(request,"id");
String ename=ParamUtil.getString(request,"name");
long phoneno =ParamUtil.getLong(request,"phone");
try {
Table1LocalServiceUtil.add(id,ename, phoneno);
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}



}
4.Table1LocalServiceImpl.java
------------------------------------------

package com.test.service.impl;

import com.liferay.portal.kernel.exception.SystemException;
import com.test.model.Table1;
import com.test.model.impl.Table1Impl;
import com.test.service.Table1LocalServiceUtil;
import com.test.service.base.Table1LocalServiceBaseImpl;
import com.test.service.persistence.Table1Persistence;


public class Table1LocalServiceImpl extends Table1LocalServiceBaseImpl {
public Table1 add(long id, String Name,long Phone) throws SystemException
{
Table1 t = new Table1Impl();
t = new Table1Impl();
t.setId(id);
t.setName(Name);
t.setPhone(Phone);
try{
t = table1Persistence.update(t, false);
}
catch(SystemException e)
{
e.printStackTrace();
}
return t;

}

}
// this code is working properly.
but i want to fetch the data from database and show it in view.jsp
but i have done it in servlet but i want to do it in Liferay.
please give me that briefly.
thumbnail
12年前 に Ravi Kumar Gupta によって更新されました。

RE: retrive data from database

Liferay Legend 投稿: 1302 参加年月日: 09/06/24 最新の投稿
Did you try these methods which are automatically created there..
Table1LocalServiceUtil.getXXX()

Use this in doview/render() or jsp to get data.
thumbnail
12年前 に Abid Ali によって更新されました。

RE: retrive data from database

Junior Member 投稿: 88 参加年月日: 12/03/31 最新の投稿
hi ravi,
I am using below code in view.jsp for getting data from database and for that i put jar file of before portlet in this portlet.
view.jsp
______
<%@page import="com.test.model.Table1" %>
<%@page import="com.test.service.*" %>
<%@page import="java.util.*" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portletefineObjects />

<%
int userCount = Table1LocalServiceUtil.getTable1sCount();
List<Table1> users = Table1LocalServiceUtil.getTable1s(0, userCount);

for (Table1 user:users)
{
out.print("ID: " + user.getId());

out.print("\nName: " + user.getName());

out.print("\nphone: " + user.getPhone());
}
%>
// but my issue is getting data according to primery key one by one and print it as a form format
how i will do it plz give the code and with description. because i new in liferay
thumbnail
12年前 に Ravi Kumar Gupta によって更新されました。

RE: retrive data from database

Liferay Legend 投稿: 1302 参加年月日: 09/06/24 最新の投稿
I am not getting what you want to say by "but my issue is getting data according to primery key one by one and print it as a form format"

But if u want to get only one record.. and u have the key/id then there are other methods also.. like for a Foo Entity
FooLocalServiceUtil.getFoo(fooId)

I hope you get this.. if not, please do let us know in a more clear way.. emoticon
thumbnail
11年前 に devaraj s によって更新されました。

RE: retrive data from database

Regular Member 投稿: 228 参加年月日: 12/05/21 最新の投稿
Hi abid,,
I have attached a PDF file go throgh that you will get a solution..
thumbnail
12年前 に Anil T によって更新されました。

RE: retrive data from database

Expert 投稿: 313 参加年月日: 12/01/14 最新の投稿
Hi Abid,

I added your above code in my new portlet and it was deployed successfully. I found one method getTable1(long id) in Table1LocalServiceUtil.
You can get the value by passing your id to above class like Table1LocalServiceUtil.getTable1(id). Try this one in jsp page.
thumbnail
10年前 に meera prince によって更新されました。

RE: retrive data from database

Liferay Legend 投稿: 1111 参加年月日: 11/02/08 最新の投稿
update the data in the mysql using jsp ,i have created the form in one jsp page and remaining logic in another jsp page.....

<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@page import="javax.portlet.PortletURL"%>
<%@page import="javax.portlet.RenderResponse"%>
<%@page import="javax.portlet.ActionRequest"%>
<%@ include file="/html/book/init.jsp" %>
<h1>Add / Edit Form</h1>

<portlet:renderURL var="renderURL ">
<portlet:param name="jspPage" value="/html/book/show.jsp"/>

</portlet:renderURL>

<aui:form name="fm" method="POST" action="<%=renderURL.toString()%>">
<aui:input name="bookId" label="enter book id"/>
<aui:input name="bookTitle" label="Enter Book Title"></aui:input>
<aui:input name="author"></aui:input>
<aui:button type="submit" value="save"></aui:button>

</aui:form>

<a href="<portlet:renderURL/>">&laquo; Go Back</a>




<%@page import="com.book.slayer.model.impl.BMSBOOKImpl"%>
<%@page import="com.liferay.taglib.portlet.RenderURLParamsTag"%>
<%@page import="com.book.slayer.service.BMSBOOKLocalService"%>
<%@page import="com.book.slayer.model.BMSBOOK"%>
<%@page import="com.book.slayer.service.BMSBOOKLocalServiceUtil"%>
<%@ include file="/html/book/init.jsp" %>
<%@ page import="java.util.*" %>
<%@ page import="com.book.slayer.*" %>
<%@ include file="/html/book/init.jsp" %>

<%
String bookTitle=request.getParameter("bookTitle");
String author=request.getParameter("author");
String bid=request.getParameter("bookId");
long bookId=Long.parseLong(bid);
BMSBOOK book=new BMSBOOKImpl();
book.setBookTitle(bookTitle);
book.setAuthor(author);
book.setBookId(bookId);
book.setDateAdded(new Date());

try{
BMSBOOKLocalServiceUtil.updateBMSBOOK(book);

}
catch (com.liferay.portal.kernel.exception.SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
%>
<h2>Data modified successfully</h2>
<h2>please click back to see the list of books. </h2>
<br/><a href="<portlet:renderURL/>">&laquo; Go Back</a>
10年前 に David Ilechukwu によって更新されました。

RE: retrive data from database

Regular Member 投稿: 154 参加年月日: 10/06/07 最新の投稿
I think Ravi Gupta's suggestion above is what you need to do.

Table1LocalServiceUtil.getXXX()
. These methods are autogenerated by ServiceBuilder for you.
If you need a step by step guide on how to get them generated on how to use them, please respond with the exact steps you have taken so far, wo that we can guide you more appropriately.

Regards
thumbnail
8年前 に Jan Geißler によって更新されました。

RE: retrive data from database

Liferay Master 投稿: 735 参加年月日: 11/07/05 最新の投稿
Please open a new Thread for a new question.
Thanks.