|
@@ -1,74 +0,0 @@
|
|
|
-package BA_Control;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.PrintWriter;
|
|
|
-import java.sql.Connection;
|
|
|
-import java.sql.DriverManager;
|
|
|
-import java.sql.PreparedStatement;
|
|
|
-//import java.sql.ResultSet;
|
|
|
-//import java.sql.Statement;
|
|
|
-import java.sql.Statement;
|
|
|
-
|
|
|
-import javax.servlet.ServletException;
|
|
|
-import javax.servlet.http.HttpServlet;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
-public class pieChange extends HttpServlet {
|
|
|
- public static final String DBURL = "jdbc:mysql://localhost:3306/kui?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8";
|
|
|
- public static final String DBUSER = "root";
|
|
|
- public static final String DBPASS = "001011";
|
|
|
- @Override
|
|
|
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
- request.setCharacterEncoding("UTF-8");
|
|
|
- response.setCharacterEncoding("UTF-8");
|
|
|
- response.setContentType("text/html;UTF-8");
|
|
|
- // 输出流
|
|
|
- PrintWriter out = response.getWriter();
|
|
|
- // 数据库连接代码
|
|
|
- try {
|
|
|
-
|
|
|
- //修改
|
|
|
- String changeName = request.getParameter("changeName");
|
|
|
- String changeScore = request.getParameter("changeScore");
|
|
|
-
|
|
|
- Connection conn = null; // 表示数据库的连接的对象
|
|
|
- //Statement stmt = null; // 表示数据库的更新操作
|
|
|
- PreparedStatement ps = null;
|
|
|
-
|
|
|
- // 1、使用Class类加载驱动程序
|
|
|
- try {
|
|
|
- Class.forName("com.mysql.jdbc.Driver");
|
|
|
- } catch (ClassNotFoundException e) {
|
|
|
- out.print("找不到driver");
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- // 2、连接数据库
|
|
|
- conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
|
|
|
- //stmt = conn.createStatement();
|
|
|
-
|
|
|
- //修改
|
|
|
- if(!changeName.equals("") && !changeScore.equals("")) {
|
|
|
- out.println("进来修改啦");
|
|
|
- try {
|
|
|
- ps = conn.prepareStatement("update pie set score =" + changeScore + " where name =\"" + changeName + "\""); //转义字符串\,因为changeName是字符串,注意这里不要手贱加了空格
|
|
|
- ps.executeUpdate();
|
|
|
- } catch (Exception e) {
|
|
|
- out.print("修改出了点问题");
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- conn.close();
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- out.flush();
|
|
|
- out.close();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|