Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
|
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 17th, 2003, 04:49 AM
Registered User
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to delete a row when click delete hyperlink

hI,

Iam pasting my code below.My problem isi retrieve rows from database and display them in jsp page in rows.For each row there is delete hyperlink.Now when i click that link i should only delete the row corresponding to that delete link temporarily but it should not delete the row from database now.It should only delete the row from database when i click the save button.How can i do this can any one give some code.

thanks
naveen
[email protected]

<%@ page language="java" import="Utils.*,java.sql.*,SQLCon.ConnectionPool,j ava.util.Vector,java.util.StringTokenizer" %>


<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Item Details</title>
<script>
function submitPage()
{
document.details.action = "itemdetails.jsp" ;
document.details.submit();
}

</script>
</head>

<body>
<form name="details" action="itemdetails.jsp" method="post">
<%

ConnectionPool pool;
Connection con = null;
Statement st;
ResultSet rs =null;

%>
<table border="0" cellpadding="0" cellspacing="0" width="328">
<tr>
<td width="323" colspan="4"><b>Reference No :</b> <input type="text" name="txt_refno" size="14">
<input type="submit" value="search" name="search" ></td>
</tr>
<tr>
<td width="81" bgcolor="#000099"><b>Item Code</b></td>
<td width="81" bgcolor="#000099"><b>Item No</b></td>
<td width="81" bgcolor="#000099"><b>Amount </b></td>
<td width="80" bgcolor="#000099"> </td>
</tr>
<%
pool= new ConnectionPool();
Utils utils = new Utils();
double total =0.00;
String search =utils.returnString(request.getParameter("search") );

if(search.equals("search"))
{
try
{



String ref_no =utils.returnString(request.getParameter("txt_refn o"));
String strSQL="select * from ref_table where refno='" + ref_no + "' ";

con = pool.getConnection();
st=con.createStatement();
rs = st.executeQuery(strSQL);
while(rs.next())
{
String itemcode=rs.getString(2);
int item_no=rs.getInt(3);
double amount= rs.getDouble(4);
total= total + amount;





%>
<tr>
<td width="81"><input type=hidden name=hitem value=<%=itemcode%>><%=itemcode%></td>
<td width="81"><input type=hidden name=hitemno value=<%=item_no%>><%=item_no%></td>
<td width="81"><input type=hidden name=hamount value=<%=amount%>><%=amount%></td>
<td width="80"><a href="">delete</a></td>
</tr>
<%
}

}catch(Exception e){}

finally {
if (con != null) pool.returnConnection(con);
}
}

%>
<tr>
<td width="323" colspan="4">
<p align="right"><b>Total:</b><input type="text" name="txt_total" size="10" value="<%=total%>"></td>
</tr>
<tr>
<td width="323" colspan="4">
<input type="button" value="save" name="save"></td>
</tr>
</table>
</form>
</body>

</html>



 
Old August 16th, 2004, 01:29 AM
Authorized User
 
Join Date: Aug 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to olupas
Default

HI,
Every time when you click the delete button,you should update a list
of deleted rows in the session.

Collection list=new LinkedList();//the list of selected rows
list.add(PK|row identifier);//add the row in the list
session.setAttribute("DeletedRows",list);//finnaly delete the rows
And finally you should delete the rows when you click save.

PS:Embedded java code in the JSP page is not the "nice".
   you should use MVC (like Struts ) http://struts.apache.org/







Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGridView - how to delete Row [email protected] C# 2005 0 November 25th, 2007 06:43 AM
Help: Right-click to delete in a datagrid nabrusim VB.NET 2002/2003 Basics 1 November 4th, 2007 12:10 PM
Accept and Delete a row in DataGrid vijay_83 ASP.NET 1.0 and 1.1 Basics 2 September 19th, 2006 12:15 PM
In datagrid when checkbox true delete in btn click ashish2001mca ASP.NET Espanol 1 January 9th, 2006 08:45 AM
Confirm delete row in datagrid rajanikrishna General .NET 3 December 8th, 2004 09:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.