<%@ page import="java.sql.*" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.lang.reflect.Parameter" %><%--
Created by IntelliJ IDEA.
User: qq316
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>
<%
String name=request.getParameter("name");
String department=request.getParameter("department");
String destination=request.getParameter("destination");
String departuredate=request.getParameter("departuredate");
String returndate=request.getParameter("returndate");
String Reason=request.getParameter("Reason");
String Startfare=request.getParameter("Startfare");
String Returnfare=request.getParameter("Returnfare");
String foodallowance=request.getParameter("foodallowance");
String localtrans=request.getParameter("localtrans");
String Accommodation=request.getParameter("Accommodation");
int totalamount=Integer.parseInt(Startfare)+Integer.parseInt(Returnfare)+Integer.parseInt(foodallowance)+Integer.parseInt(localtrans)+Integer.parseInt(Accommodation);
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/2023shenpi", "root", "123456");
Statement stat = null;
stat = conn.createStatement();
String sql = "INSERT INTO baoxiao(name,department,destination,departuredate,returndate,Reason,Startfare,Returnfare,foodallowance,localtrans,Accommodation,totalamount)VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement ps = null;
ps = conn.prepareStatement(sql);
ps.setString(1,name);
ps.setString(2,department);
ps.setString(3,destination);
ps.setString(4,departuredate);
ps.setString(5,returndate);
ps.setString(6,Reason);
ps.setString(7,Startfare);
ps.setString(8,Returnfare);
ps.setString(9,foodallowance);
ps.setString(10,localtrans);
ps.setString(11,Accommodation);
ps.setInt(12,totalamount);
int i = 0;
i = ps.executeUpdate();
out.println("成功添加" + i + "行");
stat.close();
conn.close();
%>
</body>
</html>