diff --git "a/10 \346\234\261\345\277\227\351\271\217/\344\275\234\344\270\232 (2).md" "b/10 \346\234\261\345\277\227\351\271\217/\344\275\234\344\270\232 (2).md" new file mode 100644 index 0000000000000000000000000000000000000000..ca4bd899fa707c9182126d798b1d4fa4b68dd4c4 --- /dev/null +++ "b/10 \346\234\261\345\277\227\351\271\217/\344\275\234\344\270\232 (2).md" @@ -0,0 +1,56 @@ +# 作业, + +* 1 数据库相关的操作,使用封装的工具类 + +* 2 编写四个servlet,使用注解指定相关的访问路径,分别对应查询,修改,删除,添加的操作 + +* 3 从浏览器中,访问这中个路径,显示响应的信息,查询显示结果,其它的显示成功或是失败 + +* 4 预习题:如何通过浏览器传送请求参数给servlet,servlet如何接收这些参数,并使用这些参数,去影响数据库的操作? + + ``` + package com.mxdx.servlet; + + + import javax.servlet.ServletException; + import javax.servlet.http.HttpServlet; + import javax.servlet.http.HttpServletRequest; + import javax.servlet.http.HttpServletResponse; + import java.io.IOException; + import java.sql.*; + + public class Student02 extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + System.out.println("DoGet is running ......."); + + + try { + Class.forName("com.mysql.jdbc.Driver"); + Connection conn = DriverManager.getConnection("jdbc:mysql:///student?useSSl=false&useUnicode=true&characterEncoding=utf8", "root", "123456789"); + String sql="select * from stu"; + PreparedStatement pst = conn.prepareStatement(sql); + ResultSet rst = pst.executeQuery(); + while (rst.next()){ + int id = rst.getInt("id"); + String name = rst.getString("name"); + String sex = rst.getString("sex"); + System.out.println(id+name+sex); + + } + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } + + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + super.doPost(req, resp); + } + } + ``` + +