日期:2014-05-20 浏览次数:20712 次
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DBConn conn = new DBConn(); conn.getConn(); conn.ListUser(); conn.closeConn(); }code] DBConn.java [code=Java]public void ListUser() { try { stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from users"); while (rs!=null && rs.next()) { System.out.print("<tr><td>姓名=" + rs.getString("userName") + "</td>"); System.out.print("<td>密码=" + rs.getString("userPwd") + "</td></tr>"); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public List ListUser() { try { List<Users> list=new ArrayList<List>(); Users user=null; stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from users"); while (rs.next()) { user=new Users(); user.setName(rs.getString("name")); user.setXXX(rs.getString("XXX")); . . list.add(user); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list; }