Java源代码如下:publicListgetAllMsgList(){ListmsgList=newArrayList();DBConnectiondb=newDBConnection();Connectionconn=db.getConn();Stringsql="select*frommsg...
Java 源代码如下:
public List getAllMsgList() { List msgList = new ArrayList(); DBConnection db = new DBConnection(); Connection conn = db.getConn(); String sql = "select * from msg"; try { Statement pstmt = conn.createStatement(); ResultSet rs = pstmt.executeQuery(sql); if (rs.next()) { int id = rs.getInt(1); String content = rs.getString(2); String author = rs.getString(3); String publishiTime = rs.getString(4); Msg msg = new Msg(id, content, author, publishiTime); msgList.add(msg); } rs.close(); pstmt.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } return msgList; }
main函数:
IMsgDAO dao = new MsgDAOMysqlImpl(); List msgList = dao.getAllMsgList();