Fórum

database problem

Harshitha Kotian, modificado 11 Anos atrás.

database problem

New Member Postagens: 8 Data de Entrada: 01/04/13 Postagens Recentes
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>
thumbnail
mohammad azaruddin, modificado 11 Anos atrás.

RE: database problem

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens Recentes
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, modificado 11 Anos atrás.

RE: database problem

New Member Postagens: 8 Data de Entrada: 01/04/13 Postagens Recentes
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
thumbnail
David H Nebinger, modificado 11 Anos atrás.

RE: database problem

Liferay Legend Postagens: 14915 Data de Entrada: 02/09/06 Postagens Recentes
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.
thumbnail
Manish Yadav, modificado 11 Anos atrás.

RE: database problem

Expert Postagens: 493 Data de Entrada: 26/05/12 Postagens Recentes
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
thumbnail
David H Nebinger, modificado 11 Anos atrás.

RE: database problem

Liferay Legend Postagens: 14915 Data de Entrada: 02/09/06 Postagens Recentes
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, modificado 11 Anos atrás.

RE: database problem

New Member Postagens: 8 Data de Entrada: 01/04/13 Postagens Recentes
I have checked Mr. David but in lportal database there is no table called book or Library_book
thumbnail
mohammad azaruddin, modificado 11 Anos atrás.

RE: database problem

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens Recentes
HI

post ur mail id here- l will send simple development document
Harshitha Kotian, modificado 11 Anos atrás.

RE: database problem

New Member Postagens: 8 Data de Entrada: 01/04/13 Postagens Recentes
harshitha.aimit@gmail.com
Harshitha Kotian, modificado 11 Anos atrás.

RE: database problem

New Member Postagens: 8 Data de Entrada: 01/04/13 Postagens Recentes
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:
[jar] 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
[delete] 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] Java Result: 1
[delete] Deleting: E:\liferay-portal-6.1.1-ce-ga2\plugins\liferay-plugins-sdk-6.1.1\portlets\Library-portlet\build-service-classpath.jar
[echo] Error: Could not create the Java Virtual Machine.
[echo] Error: A fatal exception has occurred. Program will exit.
[echo] Error occurred during initialization of VM
[echo] 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
thumbnail
mohammad azaruddin, modificado 11 Anos atrás.

RE: database problem

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens Recentes
Hi
harshitha try this link
Harshitha Kotian, modificado 10 Anos atrás.

RE: database problem

New Member Postagens: 8 Data de Entrada: 01/04/13 Postagens Recentes
hi
how to connect db2 to liferay
thumbnail
mohammad azaruddin, modificado 10 Anos atrás.

RE: database problem

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens Recentes
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