今日学习内容
<%@ page import="java.sql.PreparedStatement" %><%@ page import="java.sql.*" %>
<%@ page import="java.sql.DriverManager" %><%--
Created by IntelliJ IDEA.
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
int sid= Integer.parseInt(request.getParameter("sid"));
String name=request.getParameter("name");
String gender=request.getParameter("gender");
String age=request.getParameter("age");
String major=request.getParameter("major");
String grade=request.getParameter("grade");
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
request.setCharacterEncoding("utf-8");
Connection conn = null;
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/2017xuanke", "root", "123456");
Statement stat = null;
stat = conn.createStatement();
String sql = "INSERT INTO student(sid,name,gender,age,major,grade)VALUES(?,?,?,?,?,?)";
PreparedStatement ps = null;
ps = conn.prepareStatement(sql);
ps.setInt(1,sid);
ps.setString(2,name);
ps.setString(3,gender);
ps.setString(4,age);
ps.setString(5,major);
ps.setString(6,grade);
int i = 0;
i = ps.executeUpdate();
out.println("成功添加" + i + "行");
stat.close();
conn.close();
%>
</body>
</html> 标签:ps,10.24,String,setString,request,getParameter,conn From: https://www.cnblogs.com/zjm921/p/17908569.html