From 919ee8dea61323cdc307a107cefda87c45dbb0b8 Mon Sep 17 00:00:00 2001 From: sjm <2431685932@qq.com> Date: Tue, 4 Jul 2023 21:00:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=A0=B9=E6=8D=AE=E6=96=87?= =?UTF-8?q?=E7=AB=A0id=E6=9F=A5=E6=89=BEusername=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/hellogithub/dao/articleDao.java | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/com/hellogithub/dao/articleDao.java b/src/com/hellogithub/dao/articleDao.java index 8f1898f..b0bb72c 100644 --- a/src/com/hellogithub/dao/articleDao.java +++ b/src/com/hellogithub/dao/articleDao.java @@ -103,7 +103,7 @@ public class articleDao { ResultSet rs = null; String sql = "SELECT * FROM `article` WHERE articleId = ? AND isValid = 1;"; String sql1 = "UPDATE article SET readCount = readCount+1 where articleId = ?"; - articleEntity entity = null; + com.hellogithub.entity.articleEntity entity=null; try{ conn = JdbcUtils.getConnection(); preparedStatement.setInt(1, id); @@ -122,19 +122,15 @@ public class articleDao { int readcount = rs.getInt(6); String articleTitle = rs.getString(7); String articleIco = rs.getString(8); - entity.setArticleId(articleid); - entity.setUserId(userid); - entity.setArticleContent(articlecontent); - entity.setPublishTime(datetime); - entity.setIsValid(isvalid); - entity.setReadCount(readcount); - entity.setArticleTitle(articleTitle); - entity.setArticleIco(articleIco); + entity = new articleEntity( + articleid,userid,articlecontent,datetime,isvalid,readcount,articleTitle,articleIco + ); + preparedStatement1.close(); + JdbcUtils.closeConnection(rs, preparedStatement, conn); } - return entity; - } catch (Exception e) { + } catch (SQLException e) { e.printStackTrace(); - return entity; } + return entity; } } \ No newline at end of file