下面这段代码让我从jsp页面的表中删除了行,但是没有从我的数据库中删除,我该怎么做?换句话说,我需要删除行(到我的数据库),只要在我的jsp页面上选中一个复选框。我需要在数据库和jsp页面上动态删除表行。
<%@page import="java.sql.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>destcode</title>
<link rel="stylesheet" type="text/css" href="DELETE BUTTON CSS.css">
</head>
<style> Stable, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
<%
Class.forName("com.mysql.jdbc.Driver");
String myDatabase = "jdbc:mysql://localhost:3306/project_app?user=root&password=1234";
Connection myConnection = DriverManager.getConnection(myDatabase);
Statement myStatement = myConnection.createStatement();
String search=request.getParameter("search");
ResultSet rs = myStatement.executeQuery("SELECT * FROM DEST WHERE COUNTRY='"+search+"' OR CITY='"+search+"' ");
%>
<table style="width:100%">
<table id="Dest_table">
<tr>
<th> Dest. No. </th>
<th>Check </th>
<th>Country</th>
<th>City</th>
<th>Url of Destination</th>
<th>Category</th>
</tr>
<tr> <%while(rs.next()){ %>
<td> <%=rs.getString("ID_DEST") %> </td>
<td><INPUT type="checkbox" name="chk" value="checked"/></td>
<td> <%=rs.getString("COUNTRY") %></td>
<td> <%=rs.getString("CITY") %> </td>
<td> <a href=<%=rs.getString("URL") %> > <%=rs.getString("URL") %> </a>
</td>
</tr>
<% } %>
</table>
<SCRIPT language="javascript">
function deleteRow(Dest_table) {
try {
var table = document.getElementById(Dest_table);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
</SCRIPT>