code079.java
package pack02;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//��ʾͼ�飬FindServlet�࣬��code081.jsp����
@WebServlet(name = "code079",urlPatterns = "/page04/pack02.code079")
public class code079 extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
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);
Statement stmt = conn.createStatement();
String sql = "select * from tb_books";
ResultSet result = stmt.executeQuery(sql);
List<code078> list1 = new ArrayList<code078>();
while (result.next())
{
code078 book = new code078();
book.setId(result.getInt("id"));
book.setName(result.getString("name"));
book.setPrice(result.getDouble("price"));
book.setBookCount(result.getInt("bookCount"));
book.setAuthor(result.getString("author"));
list1.add(book);
}
request.setAttribute("list", list1);
result.close();
stmt.close();
conn.close();
} catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.printStackTrace();
}
request.getRequestDispatcher("code080.jsp").forward(request, response);
}
}