时间:2021-07-01 10:21:17 帮助过:5人阅读
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <html> <head> <title>更新书的信息</title> </head> <body> <form action="update_Dog.jsp" method="post"> <table align="center"> <tr> <td>请输入编号:</td> <td><input type="text" name="id" readonly="readonly" value=" <%=request.getParameter("id") %>"></td> </tr> <tr> <td>请输入新的的书名:</td> <td><input type="text" name="name" ></td> </tr> <tr> <td>请输入书的价格:</td> <td><input type="text" name="health" ></td> </tr> <tr> <td>请输入书的喜爱度:</td> <td><input type="text" name="love" ></td> </tr> <tr> <td>请输入书的作者:</td> <td><input type="text" name="strain" ></td> </tr> <tr colspan=2> <td><input type="submit" value="提交"></td> <td><input type="reset" value="重置"></td> </tr> </table> </form> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@page import="java.sql.PreparedStatement"%> <%@page import="jdbc.sqlServer"%> <%@page import="java.sql.Connection"%> <%@page import="java.sql.ResultSet"%> <% String id = request.getParameter("id"); String name = request.getParameter("name"); name = new String(name.getBytes("ISO-8859-1"),"utf-8"); String health = request.getParameter("health"); String love = request.getParameter("love"); String strain = request.getParameter("strain"); strain = new String(strain.getBytes("ISO-8859-1"),"utf-8"); //引用连接数据库方法 sqlServer sq=new sqlServer(); //得到数据库连接 Connection con = sq.getConnection(); //编写sql语句 String sql="update Dog set name=?, health=? ,love=?, strain=? where id=?"; //得到数据库操作对象 PreparedStatement st=null; st =con.prepareStatement(sql); st.setString(1,name); st.setString(2,health); st.setString(3,love); st.setString(4,strain); st.setString(5,id); // 得到查询的结果 if(st.executeUpdate()>0){ %> <script type="text/javascript"> alert("更新成功"); location="showLog.jsp"; </script> <% }else{ %> <script type="text/javascript"> alert("更新失败"); location="showLog.jsp"; </script> <% } %>
SQL Server对数据进行修改
标签: