今日学习代码
增加课程的第二部分
<%@ page import="java.sql.*" %><%@ page import="java.sql.PreparedStatement" %><%--
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 cid= Integer.parseInt(request.getParameter("cid"));
int tid= Integer.parseInt(request.getParameter("tid"));
String name=request.getParameter("name");
String t_name=request.getParameter("t_name");
String cishu=request.getParameter("cishu");
int renshu=Integer.parseInt(request.getParameter("renshu"));
String time=request.getParameter("time");
String college=request.getParameter("college");
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 course(cid,name,time,cishu,college,tid,t_name,renshu)VALUES(?,?,?,?,?,?,?,?)";
PreparedStatement ps = null;
ps = conn.prepareStatement(sql);
ps.setInt(1,cid);
ps.setString(2,name);
ps.setString(3,time);
ps.setString(4,cishu);
ps.setString(5,college);
ps.setInt(6,tid);
ps.setString(7,t_name);
ps.setInt(8,renshu);
int i = 0;
i = ps.executeUpdate();
out.println("成功添加" + i + "行");
stat.close();
conn.close();
%>
</body>
</html> 标签:10.20,ps,String,setString,request,getParameter,name From: https://www.cnblogs.com/zjm921/p/17908565.html