create table tb_article(
id int(6) not null auto_increment,
typeId int(3) not null default 8,
title varchar(30) not null default '#',
content text,
phTime timestamp,
number int(6),
primary key(id)
)default charset=utf8;
insert into tb_article(typeId,title,content,number) values(6,'喊赛票奴','好娃,上天那,蓝月呀',100);
head_main.jsp
</head>
<jsp:useBean id="articleDao" scope="request"
class="com.wy.dao.ArticleDao"></jsp:useBean>
<%
Integer typeId = null;
List articleList = articleDao.queryArticle(typeId);
int articleNumber = articleList.size();
if (articleNumber > 5) {
articleNumber = 5;
}
%>
<body>
<%
out.println("come");
%>
</body>
</html>
ArticleDao.java
public List queryArticle(Integer typeId) {
List list = new ArrayList();
String sql = null;
if (typeId == null)
sql = "select * from tb_article";
else
sql = "select * from tb_article where typeID='" + typeId
+ "' order by id desc";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
articleForm = new ArticleForm();
articleForm.setId(rs.getInt(1));
System.out.println(rs.getInt(1));
articleForm.setTypeId(rs.getInt(2));
System.out.println(rs.getInt(2));
articleForm.setTitle(rs.getString(3));
System.out.println(rs.getString(3));
articleForm.setContent(rs.getString(4));
System.out.println(rs.getString(4));
articleForm.setPhTime(rs.getString(5));
System.out.println(rs.getString(5));
articleForm.setNumber(rs.getInt(6));
System.out.println(rs.getInt(6));
list.add(articleForm);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
运行到这里,已经涉及到2个表了!但是这两个表之间没什么联系,文章并非登录用户所发表。
源代码:http://pan.baidu.com/share/link?shareid=2401642393&uk=3878681452