許多初學者停留在 JSP 內嵌 SQL 階段,本教程引導採用 OOP 思想進行 JSP 開發。
資料庫:MySQL。主表 news2:
create table news2 (
newsid int not null,
userid int,
kwid int,
title varchar(100),
content text,
hits int,
cdate varchar2(30),
mdate varchar2(30),
primary key(newsid)
);
insert into news2 (newsid, title, content) values (1, 'test title', 'test body');
News.java 封裝資料,NewsDAO.java 處理資料庫操作。getNewsByPrimaryKey、getRecentNews、getHotNews 等。後續將逐步實作 DAO 介面、工廠、實現類與測試。