天天看点

链接数据库并把表格显示出来

package wx05;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;public class BaseUserInfoDao { public List getAllinfo(){ List retval=new ArrayList(); try {try {Class.forName("");Connection connection = DriverManager.getConnection("");Statement createStatement = connection.createStatement();ResultSet rs = createStatement.executeQuery("select * from student");while(rs.next()){String UserName = rs.getString("UserName");int UserId = rs.getInt("UserId");String UserPassword = rs.getString("UserPassword");BeanUserInfoBean beanUserInfoBean = new BeanUserInfoBean(UserName, UserId, UserPassword);retval.add(beanUserInfoBean);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} return retval; }}public class BeanUserInfoBean {String UserName ;@Overridepublic String toString() {return "BeanUserInfoBean [UserName=" + UserName + ", UserId=" + UserId + ", UserPassword=" + UserPassword + "]";}public BeanUserInfoBean(String UserName, int userId, String userPassword) {super();UserName = UserName;UserId = userId;UserPassword = userPassword;}int UserId ;String UserPassword ;public String getUserName() {return UserName;}public void setUserName(String userName) {UserName = userName;}public int getUserId() {return UserId;}public void setUserId(int userId) {UserId = userId;}public String getUserPassword() {return UserPassword;}public void setUserPassword(String userPassword) {UserPassword = userPassword;}}public class Servlet extends HttpServlet {private static final long serialVersionUID = 1L; public Servlet() { super(); // TODO Auto-generated constructor stub }protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {BaseUserInfoDao baseUserInfoDao = new BaseUserInfoDao();List allinfo = baseUserInfoDao.getAllinfo();request.getSession().setAttribute("allinfo", allinfo);response.sendRedirect("show.jsp");}}<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

ID 密码 用户名

<%-- --%>