예제 #1
0
파일: Database.java 프로젝트: Meaglin/Zones
 public List<Zone> getWorld(String world) {
   Connection conn = null;
   PreparedStatement st = null;
   ResultSet rs = null;
   List<Zone> zones = new ArrayList<Zone>();
   try {
     conn = getConnection();
     st = conn.prepareStatement(SELECT_ZONES);
     st.setString(1, world);
     rs = st.executeQuery();
     Zone z = null;
     while (rs.next()) {
       if (z == null || z.getId() != rs.getInt("id")) {
         if (z != null) {
           zones.add(z);
         }
         z = new Zone();
         z.setId(rs.getInt("id"));
         z.setName(rs.getString("name"));
         z.setZonetype(rs.getString("zonetype"));
         z.setFormtype(rs.getString("formtype"));
         z.setWorld(rs.getString("world"));
         z.setAdmins(rs.getString("admins"));
         z.setUsers(rs.getString("users"));
         z.setSettings(rs.getString("settings"));
         z.setMinY(rs.getInt("minz"));
         z.setMaxY(rs.getInt("maxz"));
         z.setSize(rs.getInt("size"));
         z.setConfig(rs.getString("config"));
       }
       z.addVertice(Vertice.from(z, rs));
     }
     if (z != null) {
       zones.add(z);
     }
   } catch (Exception e) {
     Zones.log.warning("[Zones]Error loading zones of world " + world + ":");
     e.printStackTrace();
   } finally {
     try {
       if (conn != null) conn.close();
       if (st != null) st.close();
       if (rs != null) rs.close();
     } catch (Exception e) {
     }
   }
   return zones;
 }
예제 #2
0
파일: Database.java 프로젝트: Meaglin/Zones
 public Zone get(int id) {
   Connection conn = null;
   PreparedStatement st = null;
   ResultSet rs = null;
   try {
     conn = getConnection();
     st = conn.prepareStatement(SELECT_ZONE);
     st.setInt(1, id);
     rs = st.executeQuery();
     if (rs.next()) {
       Zone z = new Zone();
       z.setId(rs.getInt(1));
       z.setName(rs.getString("name"));
       z.setZonetype(rs.getString("zonetype"));
       z.setFormtype(rs.getString("formtype"));
       z.setWorld(rs.getString("world"));
       z.setAdmins(rs.getString("admins"));
       z.setUsers(rs.getString("users"));
       z.setSettings(rs.getString("settings"));
       z.setMinY(rs.getInt("minz"));
       z.setMaxY(rs.getInt("maxz"));
       z.setSize(rs.getInt("size"));
       z.setConfig(rs.getString("config"));
       z.setVertices(get(z));
       return z;
     }
   } catch (Exception e) {
     Zones.log.warning("[Zones]Error getting zone with id " + id + ":");
     e.printStackTrace();
   } finally {
     try {
       if (conn != null) conn.close();
       if (st != null) st.close();
       if (rs != null) rs.close();
     } catch (Exception e) {
     }
   }
   return null;
 }