删除:先拿到其下标,根据下标删除值
//设置字符编码
request.setCharacterEncoding("utf-8");
//接收nid
String nid=request.getParameter("nid");
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:orcl";
Connection con=DriverManager.getConnection(url, "scott","tiger");
String sql="delete news279 where nid="+nid;
PreparedStatement ps=con.prepareStatement(sql);
int n=ps.executeUpdate();
if(n>0){
//重定向
response.sendRedirect("/q4/news/admin.jsp") ;
}else{
out.print("<script>alert('删除失败!');location.href='admin.jsp'; </script>");
}
//关闭
if(con!=null&&!con.isClosed()){
con.close();
}
if(ps!=null){
ps.close();
}
修改:根据下标拿值,再把值赋值给增加界面,在增加界面进行修改
增加:拿到文本框,给文本框赋值
<%
//OracleDriver
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:orcl";
Connection con=DriverManager.getConnection(url, "scott","tiger");
String sql="select * from topic279";
PreparedStatement ps=con.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
while(rs.next()){
%>
<option value="<%= rs.getInt(1)%>"><%=rs.getString(2)%></option>
<%
}
//关闭连接
if(con!=null&&!con.isClosed()){
con.close();
}
if(ps!=null){
ps.close();
}
if(rs!=null){
rs.close();
}
%>