留言板

Simple JDBC connection related query?

thumbnail
Arun Kumar Ramachandran,修改在13 年前。

Simple JDBC connection related query?

Regular Member 帖子: 228 加入日期: 10-6-28 最近的帖子
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
thumbnail
Arun Kumar Ramachandran,修改在13 年前。

RE: Simple JDBC connection related query?

Regular Member 帖子: 228 加入日期: 10-6-28 最近的帖子
Hi all,
Give some sample program to resolve it


Thanks
Arun
thumbnail
Tanweer Ahmed .,修改在1 年前。

RE: Simple JDBC connection related query?

Expert 帖子: 322 加入日期: 10-3-11 最近的帖子
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
thumbnail
Arun Kumar Ramachandran,修改在13 年前。

RE: Simple JDBC connection related query?

Regular Member 帖子: 228 加入日期: 10-6-28 最近的帖子
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
thumbnail
Masroor Khan,修改在13 年前。

RE: Simple JDBC connection related query?

Regular Member 帖子: 124 加入日期: 08-9-9 最近的帖子
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,修改在11 年前。

RE: Simple JDBC connection related query?

New Member 帖子: 7 加入日期: 12-7-9 最近的帖子
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
thumbnail
David H Nebinger,修改在11 年前。

RE: Simple JDBC connection related query?

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
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.
thumbnail
Andew Jardine,修改在9 年前。

RE: Simple JDBC connection related query?

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
+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.