WebRoot/test.jsp

(完整代码) 3KB

package org.bs.dao.impl;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.util.ArrayList;import java.util.List;import org.bs.dao.ArticlesDao;import org.bs.model.Articles;import org.bs.utils.ConnContext;import org.bs.utils.DB;import org.bs.utils.PageContext;import org.bs.dao.ChannelDao;public class ArticlesDaoImpl extends BaseDao implements ArticlesDao {private ChannelDao channelDao = new ChannelDaoImpl();	public void save(Articles articles) {		Connection conn = ConnContext.getConn();		PreparedStatement pstmt = null;		String sql = "insert into t_articles (title),contents),channel) values(?),?),?)";		try {			pstmt = conn.prepareStatement(sql);pstmt.setString(1, articles.getTitle());pstmt.setString(2, articles.getContents());pstmt.setInt(3, articles.getChannel().getId());			pstmt.executeUpdate();		} catch (Exception e) {			throw new RuntimeException(e);		} finally {			DB.close(pstmt);		}	}	public void delete(int id) {		Connection conn = ConnContext.getConn();		PreparedStatement pstmt = null;		String sql = "delete from t_articles where id =?";		try {			pstmt = conn.prepareStatement(sql);			pstmt.setInt(1, id);			pstmt.executeUpdate();		} catch (Exception e) {			throw new RuntimeException(e);		} finally {			DB.close(pstmt);		}	}	public void update(Articles articles) {		Connection conn = ConnContext.getConn();		PreparedStatement pstmt = null;		String sql = "update t_articles set (title=?),contents=?),channel=?)"				+ " where id = ?";		try {			pstmt = conn.prepareStatement(sql);pstmt.setString(1, articles.getTitle());pstmt.setString(2, articles.getContents());pstmt.setInt(3, articles.getChannel().getId());pstmt.setInt(4, articles.getId());			pstmt.executeUpdate();		} catch (Exception e) {			throw new RuntimeException(e);		} finally {			DB.close(pstmt);		}	}	public Articles getById(int id) {		Connection conn = ConnContext.getConn();		PreparedStatement pstmt = null;		ResultSet rs = null;		Articles articles = new Articles();		String sql = "select * from t_articles where id = ?";		try {			pstmt = conn.prepareStatement(sql);			pstmt.setInt(1, id);			rs = pstmt.executeQuery();			if(rs.next()){articles.setTitle(rs.getString("title"));articles.setContents(rs.getString("contents"));articles.setChannel(channelDao.getById(rs.getInt("channel")));			}		} catch (Exception e) {			throw new RuntimeException(e);		} finally{			DB.close(pstmt);			DB.close(rs);		}		return articles;	}	public List<Articles> query() {		List<Articles> list = new ArrayList<Articles>();		Connection conn = ConnContext.getConn();		PreparedStatement pstmt = null;		ResultSet rs = null;		String sql = "select * from t_articles";		String sqlRecordsCount = "select count(*)"+sql.substring(sql.indexOf("from"));			   sql+=" limit ?,?";		PageContext.getPage().setRecordsCount(getRecordsCount(sqlRecordsCount, new Class[]{}, new Object[]{}));		try {			pstmt = conn.prepareStatement(sql);			pstmt.setInt(1, PageContext.getPage().getPageIndex());			pstmt.setInt(2, PageContext.getPage().getPageSize());			rs = pstmt.executeQuery();			while(rs.next()){				Articles articles = new Articles();articles.setTitle(rs.getString("title"));articles.setContents(rs.getString("contents"));articles.setChannel(channelDao.getById(rs.getInt("channel")));				list.add(articles);			}		} catch (Exception e) {			throw new RuntimeException(e);		} finally{			DB.close(pstmt);			DB.close(rs);		}		return list;	}}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。