Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Harshitha Kotian
database problem
5 aprile 2013 0.54
Risposta

Harshitha Kotian

Punteggio: New Member

Messaggi: 8

Data di Iscrizione: 1 aprile 2013

Messaggi recenti

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
5 aprile 2013 2.30
Risposta

Mohammad Azharuddin

Punteggio: Expert

Messaggi: 471

Data di Iscrizione: 17 settembre 2012

Messaggi recenti

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
12 aprile 2013 1.46
Risposta

Harshitha Kotian

Punteggio: New Member

Messaggi: 8

Data di Iscrizione: 1 aprile 2013

Messaggi recenti

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
12 aprile 2013 5.30
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 11113

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
12 aprile 2013 6.12
Risposta

Manish Yadav

Punteggio: Expert

Messaggi: 449

Data di Iscrizione: 26 maggio 2012

Messaggi recenti

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
12 aprile 2013 6.43
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 11113

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
14 aprile 2013 22.33
Risposta

Harshitha Kotian

Punteggio: New Member

Messaggi: 8

Data di Iscrizione: 1 aprile 2013

Messaggi recenti

I have checked Mr. David but in lportal database there is no table called book or Library_book
Mohammad Azharuddin
RE: database problem
14 aprile 2013 23.05
Risposta

Mohammad Azharuddin

Punteggio: Expert

Messaggi: 471

Data di Iscrizione: 17 settembre 2012

Messaggi recenti

HI

post ur mail id here- l will send simple development document
Harshitha Kotian
RE: database problem
14 aprile 2013 23.34
Risposta

Harshitha Kotian

Punteggio: New Member

Messaggi: 8

Data di Iscrizione: 1 aprile 2013

Messaggi recenti

harshitha.aimit@gmail.com
Harshitha Kotian
RE: database problem
15 aprile 2013 23.44
Risposta

Harshitha Kotian

Punteggio: New Member

Messaggi: 8

Data di Iscrizione: 1 aprile 2013

Messaggi recenti

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
16 aprile 2013 0.00
Risposta

Mohammad Azharuddin

Punteggio: Expert

Messaggi: 471

Data di Iscrizione: 17 settembre 2012

Messaggi recenti

Hi
harshitha try this link
Harshitha Kotian
RE: database problem
7 maggio 2013 5.15
Risposta

Harshitha Kotian

Punteggio: New Member

Messaggi: 8

Data di Iscrizione: 1 aprile 2013

Messaggi recenti

hi
how to connect db2 to liferay
Mohammad Azharuddin
RE: database problem
7 maggio 2013 6.06
Risposta

Mohammad Azharuddin

Punteggio: Expert

Messaggi: 471

Data di Iscrizione: 17 settembre 2012

Messaggi recenti

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