主题页面代码
<form action="doupdate.jsp">
<p>
<label> 主题 </label>
<select name="tid">
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
//连接数据库
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
//创建那个对象,用来执行sql语句
//查询到新闻主题的 最大编号
PreparedStatement ps = con.prepareStatement("select * from subject");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
%>
<option value="<%=rs.getInt(1)%>"><%=rs.getString(2)%></option>
<%
}
%>
</select>
</p>
<label>改为:</label>
<p>
<label> 主题 </label> <input name="tname" type="text"
class="opt_input" />
</p>
<input name="action" type="hidden" value="addnews"> <input
type="submit" value="提交" class="opt_sub" /> <input type="reset"
value="重置" class="opt_sub" />
</form>
修改主题功能代码
<%
//设置 请求的编码
request.setCharacterEncoding("utf-8");
int tid = Integer.valueOf(request.getParameter("tid"));
String tname= request.getParameter("tname");
//连接数据库 进行修改
Class.forName("oracle.jdbc.driver.OracleDriver");
//连接数据库
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
//创建那个对象,用来执行sql语句
//查询到新闻主题的 最大编号
PreparedStatement ps = con.prepareStatement("update subject set tname=? where tid="+tid);
//给占位符 赋值
ps.setString(1, tname);
int i= ps.executeUpdate();
if(i>0){
out.print("<script>alert('修改成功');location.href='update_sub.jsp'</script>");
}else{
out.print("<script>alert('修改失败');location.href='update_sub.jsp'</script>");
}
%>