フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Harshitha Kotian
database problem
2013/04/05 0:54
答え

Harshitha Kotian

ランク: New Member

投稿: 8

参加年月日: 2013/04/01

最近の投稿

Hi ....
I have problem with inserting values to the database , when i insert values to database it will store null values in the database
here i have given my coding part
hope i will get some help regarding this problem
view.jsp:
<%@include file="/html/library/init.jsp" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>

<liferay-portlet:renderURL var="updateBookURL">

<liferay-portlet:param name="jspPage" value="/html/library/update.jsp"/>

</liferay-portlet:renderURL>

<br/><a href="<%=updateBookURL %> ">Register </a>


update.jsp:
<%@include file="/html/library/init.jsp" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>

<%@page import="javax.portlet.PortletURL"%>
<%@page import="javax.portlet.ActionRequest"%>
<%@page import="javax.portlet.RenderResponse"%>
<%@page import="javax.portlet.*" %>
<%@page import="java.util.Calendar" %>
<%@include file="/html/library/init.jsp" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<liferay-portlet:renderURL var="saveBookURL">

<liferay-portlet:param name="jspPage" value="/html/library/save.jsp"/>

</liferay-portlet:renderURL>

</head>
<body>
<%
PortletURL updateBookURL=renderResponse.createActionURL();
updateBookURL.setParameter(
ActionRequest.ACTION_NAME,"updateBook");


%>

<form name="<portlet:namespace/>fm" method="post" action="<portlet:renderURL/>">

First Name:<input type="text" name="<portlet:namespace/>fname"/>
<br/><br/>
Last Name:<input type="text" name="<portlet:namespace/>lname"/>
<br/><br/>
Address:<textarea rows="4" cols="4" name="<portlet:namespace/>address" style=" width : 182px;"></textarea>
<br/><br/>
Date Of Birth:<input type="text" name="<portlet:namespace/>dob"/>
<br/><br/>
State: <select name="state">
<option selected="" value="Default">(Please select a state)</option>
<option value="dl">Delhi</option>
<option value="kr">Karnataka</option>
<option value="ap">Aandra Pradesh</option>
<option value="k">Kerla</option>
<option value="tn">Tamil Nadu</option>
<option value="mh">Maharastra</option>
<option value="up">UP</option>
<option value="mp">MP</option>
</select>
<br/><br/>
Telephone No:<input type="text" name="<portlet:namespace/>tel"/>

<br/>


<input type="submit" value="save" onclick="document.<portlet:namespace/>fm.submit()"/>
<a href="<%=saveBookURL %> ">Save </a>


</form>

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

</body>
</html>



save.jsp

<%@page import="java.text.DateFormat"%>
<%@page import="java.sql.Date"%>
<%@page import="javax.portlet.PortletURL"%>
<%@page import="javax.portlet.ActionRequest"%>
<%@page import="javax.portlet.RenderResponse"%>
<%@page import="javax.portlet.*" %>
<%@page import="java.util.Calendar" %>
<%@page import="java.sql.*" %>
<%@page import="javax.sql.*" %>
<%@include file="/html/library/init.jsp" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%@page import="java.util.*,java.sql.*,java.io.*,java.io.IOException" %>
<%
response.setContentType("text/html");
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String address=request.getParameter("address");
Integer dob=request.getIntHeader("dob");
String state=request.getParameter("state");
Integer tel=request.getIntHeader("tel");
try
{
Class.forName("com.ibm.db2.jcc.DB2Driver");
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}


System.out.println(fname);


try
{

System.out.println("starting to connect");

Connection conn = null;

System.setProperty("jdbc.drivers", "com.ibm.db2.jcc.DB2Driver");

String db2url = "jdbc:db2://localhost:50000/lportal";

String db2user = "db2admin";
String db2passwd = "db2admin";
Properties properties = System.getProperties();
properties.put("user", db2user);
properties.put("password", db2passwd);

conn = DriverManager.getConnection(db2url, properties);



System.out.println("You are connected now enterring");

Statement st=conn.createStatement();

System.out.println("you are creating statement");


st.executeUpdate("INSERT INTO HARSHITHA.REGISTER (FNAME, LNAME, ADDRESS, DOB, STATE, TEL ) VALUES ('"+fname+"', '"+lname+"', '"+address+"', '"+dob+"', '"+state+"', '"+tel+"' )");
System.out.println("you are executing");





System.out.println("Hello u r data saved in database");


//System.out.println(sql);

//PreparedStatement pst=con.prepareStatement(sql);
//pst.executeUpdate();
%>
<jsp:forward page="success.jsp"></jsp:forward>
<%

}
catch(SQLException e)
{
System.out.println("Query not executed : "+e.getMessage());

}
catch(Exception e)
{
e.printStackTrace();
}
%>

</body>
</html>
Mohammad Azharuddin
RE: database problem
2013/04/05 2:30
答え

Mohammad Azharuddin

ランク: Expert

投稿: 479

参加年月日: 2012/09/17

最近の投稿

Hi use liferay service builder to save data in database..It is easy and which liferay version you are using......?and which IDE .....?


Attach your code or try to write code InSide quotes like this

Read this-link
Harshitha Kotian
RE: database problem
2013/04/12 1:46
答え

Harshitha Kotian

ランク: New Member

投稿: 8

参加年月日: 2013/04/01

最近の投稿

Thank u sir
i m using liferay-portal-6.1
tomcat 7
DB2


sir,

I have created greeting portal and as you mentioned I did service builder and it build successfully
my question is :
1) I want to know in which database the Library_Book is located (Library is the namespace)
I am using DB2
while installing liferay i gave lportal as database in context
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource auth="Container" driverClassName="com.ibm.db2.jcc.DB2Driver" maxActive="20" name="jdbc/LiferayPool523" password="db2admin" type="javax.sql.DataSource" url="jdbc:db2://localhost:50000/lportal" username="db2admin"/>


and in portal-ext.properties

jdbc.default.driverClassName=com.ibm.db2.jcc.DB2Driver
jdbc.default.url=jdbc:db2://localhost:50000/lportal
jdbc.default.username=db2admin
jdbc.default.password=db2admin

hibernate.dialect=com.liferay.portal.dao.orm.hibernate.DB2Dialect
custom.sql.function.isnull=CAST(? AS VARCHAR(32672)) IS NULL
custom.sql.function.isnotnull=CAST(? AS VARCHAR(32672)) IS NOT NULL

but i checked in lportal there is no book table.
2) How to store or enter data to the table
David H Nebinger
RE: database problem
2013/04/12 5:30
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 11795

参加年月日: 2006/09/01

最近の投稿

Harshitha Kotian:
1) I want to know in which database the Library_Book is located (Library is the namespace)
but i checked in lportal there is no book table.


It's in there, but the table will be "Library_Book", not "Book". Liferay uses the namespace to create the table name to ensure there is no table name conflict with the Liferay tables or any other service builder setup in your environment.

2) How to store or enter data to the table


This would be done using the BookLocalServiceUtil class. You'll have a number of methods available here, including createBook()/addBook(), updateBook(), getBook(), etc.
Manish Yadav
RE: database problem
2013/04/12 6:12
答え

Manish Yadav

ランク: Expert

投稿: 469

参加年月日: 2012/05/26

最近の投稿

Hi David,

I am using service builder in my portlet.I have one problem .When service builder creating table in DB its creating with entity name only.
For eg:-
if i have namespace as Library and entity name is book then service builder creating table with name book only not Library_book
David H Nebinger
RE: database problem
2013/04/12 6:43
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 11795

参加年月日: 2006/09/01

最近の投稿

Manish Yadav:
if i have namespace as Library and entity name is book then service builder creating table with name book only not Library_book


Then that means you've set the db-name attribute on your entity. If you specify this attribute, SB will use it for the table name. If you don't use the attribute, SB will construct the name by concatenating the namespace with the entity name and the underscore separator.
Harshitha Kotian
RE: database problem
2013/04/14 22:33
答え

Harshitha Kotian

ランク: New Member

投稿: 8

参加年月日: 2013/04/01

最近の投稿

I have checked Mr. David but in lportal database there is no table called book or Library_book
Mohammad Azharuddin
RE: database problem
2013/04/14 23:05
答え

Mohammad Azharuddin

ランク: Expert

投稿: 479

参加年月日: 2012/09/17

最近の投稿

HI

post ur mail id here- l will send simple development document
Harshitha Kotian
RE: database problem
2013/04/14 23:34
答え

Harshitha Kotian

ランク: New Member

投稿: 8

参加年月日: 2013/04/01

最近の投稿

harshitha.aimit@gmail.com
Harshitha Kotian
RE: database problem
2013/04/15 23:44
答え

Harshitha Kotian

ランク: New Member

投稿: 8

参加年月日: 2013/04/01

最近の投稿

Hi Azaruddin


I tried to execute the library portlet which you gave me to refer i am able to execute it , but when i try to build service.xml its giving me an error please can you tell me how to over come this
" [Console output redirected to file:C:\Users\Harshitha\workspace\.metadata\.plugins\com.liferay.ide.eclipse.sdk\sdk.log]
Buildfile: E:\liferay-portal-6.1.1-ce-ga2\plugins\liferay-plugins-sdk-6.1.1\portlets\Library-portlet\build.xml
build-service:
Building MANIFEST-only jar: E:\liferay-portal-6.1.1-ce-ga2\plugins\liferay-plugins-sdk-6.1.1\portlets\Library-portlet\build-service-classpath.jar
Deleting: E:\liferay-portal-6.1.1-ce-ga2\plugins\liferay-plugins-sdk-6.1.1\portlets\Library-portlet\build-service-classpath.jar.manifest
Java Result: 1
Deleting: E:\liferay-portal-6.1.1-ce-ga2\plugins\liferay-plugins-sdk-6.1.1\portlets\Library-portlet\build-service-classpath.jar
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Error occurred during initialization of VM
Could not reserve enough space for object heap

BUILD FAILED
E:\liferay-portal-6.1.1-ce-ga2\plugins\liferay-plugins-sdk-6.1.1\build-common-plugin.xml:274: Service Builder generated exceptions.

Total time: 2 seconds"




and one more thing i am using DB2 and in DB2 where the table is stored i mean in which database because the pdf which you gave me in that they are using MySQL so it will store LMS_LMSBook table in the database
Mohammad Azharuddin
RE: database problem
2013/04/16 0:00
答え

Mohammad Azharuddin

ランク: Expert

投稿: 479

参加年月日: 2012/09/17

最近の投稿

Hi
harshitha try this link
Harshitha Kotian
RE: database problem
2013/05/07 5:15
答え

Harshitha Kotian

ランク: New Member

投稿: 8

参加年月日: 2013/04/01

最近の投稿

hi
how to connect db2 to liferay
Mohammad Azharuddin
RE: database problem
2013/05/07 6:06
答え

Mohammad Azharuddin

ランク: Expert

投稿: 479

参加年月日: 2012/09/17

最近の投稿

Hi
refer this link

And in portal-ext u should use these properties

jdbc.default.driverClassName=com.ibm.db2.jcc.DB2Driver
jdbc.default.url=jdbc:db2:lportal
jdbc.default.username=lportal
jdbc.default.password=lportal