Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Arun Kumar Ramachandran
Simple JDBC connection related query?
August 28, 2010 1:17 AM
Answer

Arun Kumar Ramachandran

Rank: Regular Member

Posts: 228

Join Date: June 28, 2010

Recent Posts

Hi all,
I try to use service builder, But i face ActionURL problem. so move to simple JDBC database connection. I retrieve user list from liferay DB using the following code:



<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />
<%@ page language="java" import="java.sql.*"%>
<html>
<head><title>Read from mySQL Database</title>
</head>
<body>
<p align="center"><b>Following records are selected from the 'User_' table.</b><br>&nbsp;</p>
<div align="center" width="85%">
<center>
<table border="1" borderColor="#ffe9bf" cellPadding="0" cellSpacing="0" width="658" height="63">
<tbody>
<td bgColor="#008080" width="47" align="center" height="19"><font color="#ffffff"><b>uuid_</b></font></td>
<td bgColor="#008080" width="107" height="19"><font color="#ffffff"><b>userId</b></font></td>
<td bgColor="#008080" width="224" height="19"><font color="#ffffff"><b>companyId</b></font></td>
<td bgColor="#008080" width="270" height="19"><font color="#ffffff"><b>createDate</b></font></td>
<%
String DRIVER = "com.mysql.jdbc.Driver";
Class.forName(DRIVER).newInstance();
Connection con=null;
ResultSet rst=null;
Statement stmt=null;
try{
String url="jdbc:mysql://localhost/bms?user=root&password=root";
int i=1;
con=DriverManager.getConnection(url);
stmt=con.createStatement();
rst=stmt.executeQuery("select * from user_");
while(rst.next()){
if (i==(i/2)*2){
%>
<tr>
<td bgColor="#ffff98" vAlign="top" width="47" align="center" height="19"><%=i%>.</td>
<td bgColor="#ffff98" vAlign="top" width="107" height="19"><%=rst.getString(2)%></td>
<td bgColor="#ffff98" vAlign="top" width="224" height="19"><a href="<%=rst.getString(3)%>"><%=rst.getString(3)%></a>&nbsp;</td>
<td bgColor="#ffff98" vAlign="top" width="270" height="19"><%=rst.getString(4)%></td>
</tr>
<%
}else{
%>
<tr>
<td bgColor="#ffcc68" vAlign="top" width="47" align="center" height="19"><%=i%>.</td>
<td bgColor="#ffcc68" vAlign="top" width="107" height="19"><%=rst.getString(2)%></td>
<td bgColor="#ffcc68" vAlign="top" width="224" height="19"><a href="<%=rst.getString(3)%>"><%=rst.getString(3)%></a>&nbsp;</td>
<td bgColor="#ffcc68" vAlign="top" width="270" height="19"><%=rst.getString(4)%></td>
</tr>
<% }
i++;
}
rst.close();
stmt.close();
con.close();
}catch(Exception e){
System.out.println(e.getMessage());
}
%>
</tbody>
</table>
</center>
</div>
</body>
</html>



But i need to ADD,DELETE,UPDATE OPTION. How to do this. Any help from forum users.I am in very urgent posistion to complete the task.Please reply as soon as possible.



Thanks
Arun
Arun Kumar Ramachandran
RE: Simple JDBC connection related query?
August 30, 2010 2:48 AM
Answer

Arun Kumar Ramachandran

Rank: Regular Member

Posts: 228

Join Date: June 28, 2010

Recent Posts

Hi all,
Give some sample program to resolve it


Thanks
Arun
Tanweer .
RE: Simple JDBC connection related query?
November 15, 2014 12:04 PM
Answer

Tanweer .

Rank: Expert

Posts: 319

Join Date: March 11, 2010

Recent Posts

Hi Arun ,

Try to minimize the JDBC codes in Liferay as much as possible.You can use the Finder methods in Liferay to retrieve the values from the database.Have a look at my blog on Finder methods Here
Arun Kumar Ramachandran
RE: Simple JDBC connection related query?
August 30, 2010 10:15 PM
Answer

Arun Kumar Ramachandran

Rank: Regular Member

Posts: 228

Join Date: June 28, 2010

Recent Posts

Hi Tanweer ,
Thanks for your reply. Its a great post. The problem i got in <form action="process.jsp" method="post">. Action was not working . I use ActionURl tag but it seems to be incorrect any sample for that Action process in portlet.



Thanks
Arun
Masroor Khan
RE: Simple JDBC connection related query?
August 31, 2010 12:37 AM
Answer

Masroor Khan

Rank: Regular Member

Posts: 119

Join Date: September 9, 2008

Recent Posts

Hi,

you can create url like that

Creating RenderURL
----------------------

PortletURL url = ((RenderResponseImpl)res).createRenderURL();
url.setParameter("struts_action", "/humanresource/employee/view_employee");
url.setWindowState(WindowState.MAXIMIZED);



Creating ActionURL
----------------------

PortletURL url = ((ActionResponseImpl)res).createActionURL();
url.setParameter("struts_action", "/humanresource/employee/view_employee");
url.setWindowState(WindowState.MAXIMIZED);


Regards,

Masroor Khan
Phat Huynh
RE: Simple JDBC connection related query?
July 17, 2012 11:22 AM
Answer

Phat Huynh

Rank: New Member

Posts: 7

Join Date: July 9, 2012

Recent Posts

Your post http://www.mpowerglobal.com/web/guest/blog/-/blogs/finder-methods-in-liferay?_33_redirect=%2Fweb%2Fguest%2Fblog has died, please show us again emoticon
David H Nebinger
RE: Simple JDBC connection related query?
July 17, 2012 1:01 PM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11102

Join Date: September 1, 2006

Recent Posts

You don't need his ad-laden blog to learn how to use ServiceBuilder. There's plenty of doco here on liferay.com (without ads), there's plenty of books, there's official Liferay training too.

Basically you should never use JDBC directly in your portlet code. You end up managing a bunch of connections and all sorts of other issues. Use ServiceBuilder to generate all of your database entity retrievals.
Andrew Jardine
RE: Simple JDBC connection related query?
November 15, 2014 12:46 PM
Answer

Andrew Jardine

Community Moderator

Rank: Liferay Legend

Posts: 1062

Join Date: December 22, 2010

Recent Posts

+1 to David. And the argument of "I don't want to store my data inside the same Schema as Liferay" -- before you use it, is irrelevant. Service Build also provides a way for you to store you information in external schemas using the data-source attribute. Service Builder is like a poster child for advertising Liferay -- try googling "liferay service builder example" if you don't like Liferay's own explanation. There are a million tutorials for it out there.