掲示板

Simple JDBC connection related query?

thumbnail
13年前 に Arun Kumar Ramachandran によって更新されました。

Simple JDBC connection related query?

Regular Member 投稿: 228 参加年月日: 10/06/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
13年前 に Arun Kumar Ramachandran によって更新されました。

RE: Simple JDBC connection related query?

Regular Member 投稿: 228 参加年月日: 10/06/28 最新の投稿
Hi all,
Give some sample program to resolve it


Thanks
Arun
thumbnail
1年前 に Tanweer Ahmed . によって更新されました。

RE: Simple JDBC connection related query?

Expert 投稿: 322 参加年月日: 10/03/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
13年前 に Arun Kumar Ramachandran によって更新されました。

RE: Simple JDBC connection related query?

Regular Member 投稿: 228 参加年月日: 10/06/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
13年前 に Masroor Khan によって更新されました。

RE: Simple JDBC connection related query?

Regular Member 投稿: 124 参加年月日: 08/09/09 最新の投稿
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
11年前 に Phat Huynh によって更新されました。

RE: Simple JDBC connection related query?

New Member 投稿: 7 参加年月日: 12/07/09 最新の投稿
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
11年前 に David H Nebinger によって更新されました。

RE: Simple JDBC connection related query?

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
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
9年前 に Andew Jardine によって更新されました。

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.