时间:2021-07-01 10:21:17 帮助过:5人阅读
处理提交的语句:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@page import="jdbc.sqlServer"%> <%@page import="java.sql.Connection"%> <%@page import="java.sql.ResultSet"%> <%@page import="java.sql.PreparedStatement"%> <% 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="insert into Dog values (?,?,?,?)"; //得到数据库操作对象 PreparedStatement st =con.prepareStatement(sql); st.setString(1,name); st.setString(2,health); st.setString(3,request.getParameter("love")); st.setString(4,strain); // 得到查询的结果 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对数据进行添加
标签: