jeudi 29 mai 2014

Java - suppression vérifié des enregistrements de base de données - Stack Overflow


I want to remove checkbox selected entries from a web application to be removed from my database.I had a code in javascript to remove those rows of my table from the jsp page .But where and how to remove the entries from my database too.


Code to delete the checked rows is as follow:


Javascript :


function upTo(tagName, root) {
if (!root) return;
tagName = tagName.toLowerCase();
while ((root = root.parentNode)) {
if (root.tagName && root.tagName.toLowerCase() == tagName) {
return root;
}
}
}

function deleteRow(el) {
var row = upTo('tr', el);
if (row) row.parentNode.removeChild(row);
}

function deleteRows() {
var flags = document.querySelectorAll('.deleteRowFlag');
for (var i=0, iLen=flags.length; i<iLen; i++) {
if (flags[i].checked) {
deleteRow(flags[i]);
}
}
}

HTML part :


<table>
<tr>
<td><input type="checkbox" class="deleteRowFlag">
<td>foo
<tr>
<td><input type="checkbox" class="deleteRowFlag">
<td>bar
</table>

<checkbox onclick="deleteRows();">Delete checked rows</button>

How to delete the coresponding details from my database too.Each row has a unique messageID say in my database.


The above html is just example dummy.Actual table is fetched like this :


    <div id="dtl_table"><table border='3' cellpadding='5'  cellspacing="0"> 
<% while(rs.next())
{ %>


<%
String messageid=rs.getString("MESSAGE_ID");
String sendername=rs.getString("EMAIL_FROM");
String messagesubject=rs.getString("EMAIL_SUBJECT");
Timestamp sendingtime=rs.getTimestamp("EMAIL_TIME");
String readstatus=rs.getString("READSTATUS");
Boolean readornot=false;%>
<%
if(readstatus.compareTo("NO")==0){
readornot=false;
%>
<tr bgcolor="#5D1B90" color="#FFFFFF" onmouseover="ChangeColor(this, true,false);" onmouseout="ChangeColor(this, false,false);" onclick="DoNav('showmail.jsp?mid=<%=messageid%>');">
<td><input type="checkbox" onclick="DoRemove(event);" width="20" class="select_all_mail"></td>
<td callspan="3" width="1000px"><%=sendername%> : <%=messagesubject%> <%=sendingtime%></td>

</tr>
<%}%>

<%
if(readstatus.compareTo("YES")==0){
readornot=true;
%>

<tr bgcolor="#5D7B9D" color="#FFFFFF" onmouseover="ChangeColor(this, true,true);" onmouseout="ChangeColor(this, false,true);" onclick="DoNav('showmail.jsp?mid=<%=messageid%>');">
<td><input type="checkbox" onclick="DoRemove(event);" width="20" class="select_all_mail"></td>
<td callspan="3" width="1000px"><%=sendername%> : <%=messagesubject%> <%=sendingtime%></td>
</tr>
<%}%>


<tr/>

<%

} %>
</tr>
</table></div>


I want to remove checkbox selected entries from a web application to be removed from my database.I had a code in javascript to remove those rows of my table from the jsp page .But where and how to remove the entries from my database too.


Code to delete the checked rows is as follow:


Javascript :


function upTo(tagName, root) {
if (!root) return;
tagName = tagName.toLowerCase();
while ((root = root.parentNode)) {
if (root.tagName && root.tagName.toLowerCase() == tagName) {
return root;
}
}
}

function deleteRow(el) {
var row = upTo('tr', el);
if (row) row.parentNode.removeChild(row);
}

function deleteRows() {
var flags = document.querySelectorAll('.deleteRowFlag');
for (var i=0, iLen=flags.length; i<iLen; i++) {
if (flags[i].checked) {
deleteRow(flags[i]);
}
}
}

HTML part :


<table>
<tr>
<td><input type="checkbox" class="deleteRowFlag">
<td>foo
<tr>
<td><input type="checkbox" class="deleteRowFlag">
<td>bar
</table>

<checkbox onclick="deleteRows();">Delete checked rows</button>

How to delete the coresponding details from my database too.Each row has a unique messageID say in my database.


The above html is just example dummy.Actual table is fetched like this :


    <div id="dtl_table"><table border='3' cellpadding='5'  cellspacing="0"> 
<% while(rs.next())
{ %>


<%
String messageid=rs.getString("MESSAGE_ID");
String sendername=rs.getString("EMAIL_FROM");
String messagesubject=rs.getString("EMAIL_SUBJECT");
Timestamp sendingtime=rs.getTimestamp("EMAIL_TIME");
String readstatus=rs.getString("READSTATUS");
Boolean readornot=false;%>
<%
if(readstatus.compareTo("NO")==0){
readornot=false;
%>
<tr bgcolor="#5D1B90" color="#FFFFFF" onmouseover="ChangeColor(this, true,false);" onmouseout="ChangeColor(this, false,false);" onclick="DoNav('showmail.jsp?mid=<%=messageid%>');">
<td><input type="checkbox" onclick="DoRemove(event);" width="20" class="select_all_mail"></td>
<td callspan="3" width="1000px"><%=sendername%> : <%=messagesubject%> <%=sendingtime%></td>

</tr>
<%}%>

<%
if(readstatus.compareTo("YES")==0){
readornot=true;
%>

<tr bgcolor="#5D7B9D" color="#FFFFFF" onmouseover="ChangeColor(this, true,true);" onmouseout="ChangeColor(this, false,true);" onclick="DoNav('showmail.jsp?mid=<%=messageid%>');">
<td><input type="checkbox" onclick="DoRemove(event);" width="20" class="select_all_mail"></td>
<td callspan="3" width="1000px"><%=sendername%> : <%=messagesubject%> <%=sendingtime%></td>
</tr>
<%}%>


<tr/>

<%

} %>
</tr>
</table></div>

0 commentaires:

Enregistrer un commentaire