code082.java
package pack02;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//UpdateServlet�࣬��code080.jsp������ã��������ݿ�
@WebServlet(name = "code082",urlPatterns = "/page04/pack02.code082")
public class code082 extends HttpServlet
{
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
int id = Integer.valueOf(request.getParameter("id"));
int bookCount = Integer.valueOf(request.getParameter("bookCount"));
try
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String pwd = "mysql123";
Connection conn = DriverManager.getConnection(url,user,pwd);
String sql = "update tb_books set bookCount = ? where id = ?";
PreparedStatement param = conn.prepareStatement(sql);
param.setInt(1, bookCount);
param.setInt(2, id);
param.executeUpdate();
param.close();
conn.close();
} catch (Exception e)
{
e.printStackTrace();
}
response.sendRedirect("pack02.code079"); //������Ϻ���FindServlet�࣬��ʾ���ݿ�����
}
}