flymis/src/com/fly/dao/NewsDAO.java
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
package com.fly.dao;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;
import com.fly.db.DBConn;
import com.fly.vo.NewsVO;
public class NewsDAO {
// 定义连接对象
private Connection conn = null;
// 定义预编译对象
private PreparedStatement pstm = null;
// 定义结果集对象
private ResultSet rs = null;
public void addNews(NewsVO news) {
try {
conn = DBConn.getConnection();
pstm = conn.prepareStatement("insert into tb_news values(?,?,?,?)");
pstm.setString(1, news.getNewsTitle());
pstm.setString(2, news.getNewsContent());
pstm.setString(3, news.getNewsTime());
pstm.setString(4, news.getUsername());
pstm.executeUpdate();
System.out.println("添加成功");
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBConn.closePreparedStatement(pstm);
DBConn.closeConnection(conn);
}
}
public List newsList() {
List<NewsVO> list = new ArrayList<NewsVO>();
NewsVO news = null;
try {
conn = DBConn.getConnection();
pstm = conn.prepareStatement("select * from tb_news order by new_time desc");
rs = pstm.executeQuery();
while (rs.next()) {
news = new NewsVO();
news.setNewsTitle(rs.getString(1));
news.setNewsContent(rs.getString(2));
news.setNewsTime(rs.getString(3));
news.setUsername(rs.getString(4));
news.setId(rs.getShort(5));
list.add(news);
后面还有 77 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。