public static List<Grouptype> getGroup(User user) { List<Grouptype> users = new ArrayList<Grouptype>(); Connection conn = DB.getConn(); String sql = ""; if (UserManager.checkPermissions(user, Group.Manger)) { sql = "select * from mdgrouptype "; } else { sql = "select * from mdgrouptype "; } Statement stmt = DB.getStatement(conn); ResultSet rs = DB.getResultSet(stmt, sql); try { while (rs.next()) { Grouptype g = GrouptypeManager.getGroupFromRs(rs); users.add(g); } } catch (SQLException e) { e.printStackTrace(); } finally { DB.close(rs); DB.close(stmt); DB.close(conn); } return users; }
public static boolean update(String c, String bid) { Connection conn = DB.getConn(); String sql = "update mdgrouptype set gname = ? where id = " + bid; PreparedStatement pstmt = DB.prepare(conn, sql); try { pstmt.setString(1, c); pstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { DB.close(pstmt); DB.close(conn); } return true; }
public static boolean save(String c) { Connection conn = DB.getConn(); String sql = "insert into mdgrouptype(id,gname,statues) values (null, ?,?)"; PreparedStatement pstmt = DB.prepare(conn, sql); try { pstmt.setString(1, c); pstmt.setInt(2, 0); pstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { DB.close(pstmt); DB.close(conn); } return true; }
public static Grouptype getGrouptype(int id) { Grouptype g = new Grouptype(); Connection conn = DB.getConn(); String sql = "select * from mdgrouptype where id = " + id; Statement stmt = DB.getStatement(conn); ResultSet rs = DB.getResultSet(stmt, sql); try { while (rs.next()) { g = GrouptypeManager.getGroupFromRs(rs); } } catch (SQLException e) { e.printStackTrace(); } finally { DB.close(rs); DB.close(stmt); DB.close(conn); } return g; }
public static int getgrouptype(int id) { int type = 0; Connection conn = DB.getConn(); String sql = "select * from mdgrouptype where type = " + id; Statement stmt = DB.getStatement(conn); ResultSet rs = DB.getResultSet(stmt, sql); try { while (rs.next()) { Grouptype branch = getGroupFromRs(rs); type = branch.getId(); } } catch (SQLException e) { e.printStackTrace(); } finally { DB.close(rs); DB.close(stmt); DB.close(conn); } return type; }
/** * Main para testar a base de dados * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { DB database = new DB("db"); database.addFile("1ijfj2382u5m98u85u2", "bino.jpg", 3); database.addFile("3jf92rf28ur2mu24umr", "lel.gif", 5); database.addFile("jf29r924r9249ru29ru", "OMG.png", 10); System.out.println(database.getChunkNumberbyFileID("1ijfj2382u5m98u85u2")); System.out.println(database.getFileNamebyFileID("1ijfj2382u5m98u85u2")); System.out.println(database.getFileIDbyFileName("lel.gif")); String bla = database.getFileIDbyFileName("lel.gif"); if (bla == null) System.out.println("NOPE"); database.close(); }
public static int delete(User user, String ptype) { List<Group> list = GroupManager.getGroup(user, Integer.valueOf(ptype)); List<Group> listg = GroupManager.getGroupdown(user, Integer.valueOf(ptype), 1); if (list != null && list.size() > 0 || listg != null && listg.size() > 0) { return -1; } int count = 0; Connection conn = DB.getConn(); String sql = "delete from mdgrouptype where id = " + ptype; logger.info(sql); Statement stmt = DB.getStatement(conn); try { count = DB.executeUpdate(stmt, sql); } finally { DB.close(stmt); DB.close(conn); } return count; }