public int upatePost(Post post) { int count = 0; try { count = executeUpdate(ReflectUtil.reflect(post, true)); } catch (Exception e) { e.printStackTrace(); } finally { closeConn(); } return count; }
public Post getPostById(String pid) { String sql = "select * from t_post where pid =" + pid; ResultSet rs = executeSQL(sql); Post post = null; try { if (rs.next()) { post = (Post) ReflectUtil.fillData(new Post(), rs); } } catch (Exception e) { e.printStackTrace(); } finally { closeConn(); } return post; }
public List<Post> getPostList(int index, int num) { String sql = "SELECT * from t_post order by pid desc LIMIT " + index + "," + num; ResultSet rs = executeSQL(sql); List<Post> list = new ArrayList<Post>(); try { while (rs.next()) { list.add((Post) ReflectUtil.fillData(new Post(), rs)); } } catch (Exception e) { e.printStackTrace(); } finally { closeConn(); } return list; }
public int newPost(Post post) { int pid = -1; try { int count = executeUpdate(ReflectUtil.reflect(post, false)); if (count == 1) { ResultSet rs = executeSQL("select LAST_INSERT_ID()"); rs.next(); pid = rs.getInt(1); } } catch (Exception e) { e.printStackTrace(); } finally { closeConn(); } return pid; }