diff --git a/src/com/hellogithub/dao/AdminDao.java b/src/com/hellogithub/dao/AdminDao.java index f3c356f..f071027 100644 --- a/src/com/hellogithub/dao/AdminDao.java +++ b/src/com/hellogithub/dao/AdminDao.java @@ -45,6 +45,7 @@ public class AdminDao { QueryRunner runner = new QueryRunner(); String sql="UPDATE admin SET loginTime = ? WHERE adminName= ? and isValid = 1"; num = runner.update(conn,sql,loginTime,name); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -127,6 +128,7 @@ public class AdminDao { QueryRunner runner = new QueryRunner(); String sql="select * from admin"; adminEntityList = runner.query(conn,sql,new BeanListHandler<>(adminEntity.class)); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -141,6 +143,7 @@ public class AdminDao { QueryRunner runner = new QueryRunner(); String sql="update admin set adminName = ? , adminPassword = ?, loginTime = ? ,isValid =? where adminId =? "; num = runner.update(conn,sql,adminName, adminPassword,loginTime, isValid,adminId); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -155,6 +158,7 @@ public class AdminDao { QueryRunner runner = new QueryRunner(); String sql="delete from admin where adminId = ?"; num = runner.update(conn,sql,id); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -169,6 +173,7 @@ public class AdminDao { QueryRunner runner = new QueryRunner(); String sql="UPDATE user SET isValid = ? WHERE userId = ?"; num = runner.update(conn, sql, isvalid,id); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -182,6 +187,7 @@ public class AdminDao { QueryRunner runner = new QueryRunner(); String sql="UPDATE project SET isValid = ? WHERE userId = ?"; num = runner.update(conn, sql, isvalid,id); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -196,6 +202,7 @@ public class AdminDao { QueryRunner runner = new QueryRunner(); String sql="UPDATE comment SET isValid = ? WHERE userId = ?"; num = runner.update(conn, sql, isvalid,id); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -210,6 +217,7 @@ public class AdminDao { QueryRunner runner = new QueryRunner(); String sql="UPDATE category SET isValid = ? WHERE userId = ?"; num = runner.update(conn, sql, isvalid,id); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -224,6 +232,7 @@ public class AdminDao { QueryRunner runner = new QueryRunner(); String sql="UPDATE article SET isValid = ? WHERE userId = ?"; num = runner.update(conn, sql, isvalid,id); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -238,6 +247,7 @@ public class AdminDao { QueryRunner runner = new QueryRunner(); String sql="UPDATE admin SET isValid = ? WHERE userId = ?"; num = runner.update(conn, sql, isvalid,id); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } diff --git a/src/com/hellogithub/dao/articleDao.java b/src/com/hellogithub/dao/articleDao.java index 43b465e..783af7a 100644 --- a/src/com/hellogithub/dao/articleDao.java +++ b/src/com/hellogithub/dao/articleDao.java @@ -222,6 +222,7 @@ public class articleDao { QueryRunner runner = new QueryRunner(); String sql="select * from article"; articleEntityList = runner.query(conn,sql,new BeanListHandler<>(articleEntity.class)); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -236,6 +237,7 @@ public class articleDao { QueryRunner runner = new QueryRunner(); String sql="update article set userId = ? , articleContent = ? , publishTime = ? ,isValid =?, readCount=?, articleTitle=?, articleIco=? where articleId =? "; num = runner.update(conn,sql,userId, articleContent , publishTime , isValid, readCount, articleTitle, articleIco ,articleId); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -250,6 +252,7 @@ public class articleDao { QueryRunner runner = new QueryRunner(); String sql="delete from article where articleId = ?"; num = runner.update(conn,sql,id); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } diff --git a/src/com/hellogithub/dao/categoryDao.java b/src/com/hellogithub/dao/categoryDao.java index f3f9b94..da51c9f 100644 --- a/src/com/hellogithub/dao/categoryDao.java +++ b/src/com/hellogithub/dao/categoryDao.java @@ -56,6 +56,7 @@ public class categoryDao { QueryRunner runner = new QueryRunner(); String sql="select * from category "; categoryEntityList = runner.query(conn,sql,new BeanListHandler<>(categoryEntity.class)); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -70,6 +71,7 @@ public class categoryDao { QueryRunner runner = new QueryRunner(); String sql="update category set category = ? , categoryName = ? ,isValid =? where categoryId =? "; num = runner.update(conn,sql,category, categoryName, isValid,categoryId); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -84,6 +86,7 @@ public class categoryDao { QueryRunner runner = new QueryRunner(); String sql="delete from category where articleId = ?"; num = runner.update(conn,sql,id); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } diff --git a/src/com/hellogithub/dao/commentDao.java b/src/com/hellogithub/dao/commentDao.java index c287bb9..65c295b 100644 --- a/src/com/hellogithub/dao/commentDao.java +++ b/src/com/hellogithub/dao/commentDao.java @@ -116,6 +116,7 @@ public class commentDao { QueryRunner runner = new QueryRunner(); String sql="select * from comment "; commentEntityList = runner.query(conn,sql,new BeanListHandler<>(commentEntity.class)); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -130,6 +131,7 @@ public class commentDao { QueryRunner runner = new QueryRunner(); String sql="update comment set userId = ? , projectId = ? , content = ? ,isUsed =?, commentTime=?, isValid=?,star=?,likeNum=?where commentId =? "; num = runner.update(conn,sql,userId, projectId , content , isUsed, commentTime, isValid, star, likeNum ,commentId); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -144,6 +146,7 @@ public class commentDao { QueryRunner runner = new QueryRunner(); String sql="delete from comment where commentId = ?"; num = runner.update(conn,sql,id); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } diff --git a/src/com/hellogithub/dao/githubDao.java b/src/com/hellogithub/dao/githubDao.java index ff5315d..b261de7 100644 --- a/src/com/hellogithub/dao/githubDao.java +++ b/src/com/hellogithub/dao/githubDao.java @@ -67,6 +67,7 @@ public class githubDao { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); githubEntityList = runner.query(conn,sql,new BeanHandler<>(githubEntity.class),projectid); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } diff --git a/src/com/hellogithub/dao/projectDao.java b/src/com/hellogithub/dao/projectDao.java index 1113451..8c20a17 100644 --- a/src/com/hellogithub/dao/projectDao.java +++ b/src/com/hellogithub/dao/projectDao.java @@ -324,6 +324,7 @@ public class projectDao { return 1; else return 0; + } catch (SQLException e) { throw new RuntimeException(e); } @@ -343,6 +344,7 @@ public class projectDao { QueryRunner runner = new QueryRunner(); String sql="select * from project "; projectEntityList = runner.query(conn,sql,new BeanListHandler<>(projectEntity.class)); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -357,6 +359,7 @@ public class projectDao { QueryRunner runner = new QueryRunner(); String sql="update project set userId = ? , projectName = ? , projectUrl = ? ,projectIco =?, projectTitle=?, projectDescription=?,startNum=?,submitTime=?,categoryId=?,isValid=? ,fileAddress = ? , periodicals = ? ,lookCount = ? where projectId =? "; num = runner.update(conn,sql,userId, projectName , projectUrl , projectIco, projectTitle, projectDescription, startNum, submitTime ,categoryId,isValid,fileAddress,periodicals,lookCount,projectId); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } @@ -375,6 +378,7 @@ public class projectDao { runner.update(conn,sql,id); sql="delete from project_category where projectId = ?"; runner.update(conn,sql,id); + conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } diff --git a/src/com/hellogithub/service/projectService.java b/src/com/hellogithub/service/projectService.java index 4d54c6b..adb823e 100644 --- a/src/com/hellogithub/service/projectService.java +++ b/src/com/hellogithub/service/projectService.java @@ -195,21 +195,34 @@ public class projectService { long t = System.currentTimeMillis(); Random random = new Random(t); List projectEntityList1 = projectDao.retLatestProject(); - Set integers =new HashSet<>(); - while(integers.size()<5){ - int num = random.nextInt(projectEntityList1.size()); - integers.add(num); - } - Iterator it = integers.iterator(); - while(it.hasNext()) + if(projectEntityList1.size()<5) { - int id = it.next(); - projectEntity projectEntity =projectEntityList1.get(id); - categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId()); - projectEntity.setCategoryName(categoryEntity.getCategoryName()); - projectEntityList.add(projectEntity); + for(int i=0;i integers =new HashSet<>(); + while(integers.size()<5){ + int num = random.nextInt(projectEntityList1.size()); + integers.add(num); + } + Iterator it = integers.iterator(); + while(it.hasNext()) + { + int id = it.next(); + projectEntity projectEntity =projectEntityList1.get(id); + categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId()); + projectEntity.setCategoryName(categoryEntity.getCategoryName()); + projectEntityList.add(projectEntity); + } } + + return projectEntityList; } public String retProjectByUserId(int id){