我有一个jsp文件,可以从用户那里获取员工ID输入。我希望将该输入发送到MySQL表中。我该怎么做?
<springForm:form method="POST" commandName="employee"
<table>
<tr>
<td>Employee ID:</td>
<td><springForm:input path="id" /></td>
<td><springForm:errors path="id" cssClass="error" /></td>
</tr>
....
<%
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sakila","root","2scream4");
PreparedStatement stat = con.prepareStatement("Insert into employee(id) VALUES(?)");
...
答案 0 :(得分:0)
你做一个int id = request.getParameter("id");
并将其传递给你准备好的陈述。
PreparedStatement stat = con.prepareStatement("Insert into table_name VALUES(?)");
stat.setInt(1, id);