Beispiel #1
1
  /**
   * @deprecated use getAllModules instead. Doesn't twerk.
   * @return
   */
  public List<Module> getModules() {
    List<Module> modules = new ArrayList<Module>();

    ResultSet result = db.preformQuery("Select * From module");

    try {
      while (result.next()) {
        List links = new ArrayList();
        links = getModuleLinks(result.getString("moduleID"));
        Module module =
            new Module(
                result.getString("moduleID"),
                result.getString("moduleName"),
                result.getString("moduleSummery"),
                result.getString("moduleDescription"),
                links);
        modules.add(module);
      }

    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR, e.toString(), "Problem with getting all modules");
    }

    return modules;
  }
 /**
  * Returns job information in the DDBB.
  *
  * @param jobId the job identification.
  * @return the {@link eu.aliada.ckancreation.model.Job} which contains the job information.
  * @since 2.0
  */
 public Job getJob(final int jobId) {
   // Get the job information from the DDBB
   final Job job = new Job();
   job.setId(jobId);
   try {
     final Statement sta = getConnection().createStatement();
     final String sql = "SELECT * FROM ckancreation_job_instances WHERE job_id=" + jobId;
     final ResultSet resultSet = sta.executeQuery(sql);
     while (resultSet.next()) {
       job.setStartDate(resultSet.getTimestamp("start_date"));
       job.setEndDate(resultSet.getTimestamp("end_date"));
       job.setCkanOrgURL(resultSet.getString("ckan_org_url"));
       job.setCkanDatasetURL(resultSet.getString("ckan_dataset_url"));
       // Determine job status
       String status = JOB_STATUS_IDLE;
       if (job.getStartDate() != null) {
         status = JOB_STATUS_RUNNING;
         if (job.getEndDate() != null) {
           status = JOB_STATUS_FINISHED;
         }
       }
       job.setStatus(status);
     }
     resultSet.close();
     sta.close();
   } catch (SQLException exception) {
     LOGGER.error(MessageCatalog._00024_DATA_ACCESS_FAILURE, exception);
     return null;
   }
   return job;
 }
  private FileContent getFileContentWithChunkChecksums(FileChecksum fileChecksum) {
    try (PreparedStatement preparedStatement =
        getStatement("filecontent.select.all.getFileContentByChecksumWithChunkChecksums.sql")) {
      preparedStatement.setString(1, fileChecksum.toString());

      try (ResultSet resultSet = preparedStatement.executeQuery()) {
        FileContent fileContent = null;

        while (resultSet.next()) {
          if (fileContent == null) {
            fileContent = new FileContent();

            fileContent.setChecksum(
                FileChecksum.parseFileChecksum(resultSet.getString("checksum")));
            fileContent.setSize(resultSet.getLong("size"));
          }

          // Add chunk references
          ChunkChecksum chunkChecksum =
              ChunkChecksum.parseChunkChecksum(resultSet.getString("chunk_checksum"));
          fileContent.addChunk(chunkChecksum);
        }

        return fileContent;
      }
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
Beispiel #4
0
  @Override
  public Client search(int id) {

    ResultSet resultSet = null;
    try {
      preparedStatement = connection.prepareStatement("SELECT * FROM clients");
      resultSet = preparedStatement.executeQuery();

      while (resultSet.next()) {
        if (Integer.valueOf(resultSet.getString("id_client")) == id) {
          return new Client(
              resultSet.getString("name"),
              resultSet.getString("login"),
              resultSet.getString("phone"),
              resultSet.getString("email"),
              resultSet.getString("password"));
        }
      }

    } catch (SQLException e) {
      e.printStackTrace();
    }

    return null;
  }
Beispiel #5
0
  /**
   * @param user
   * @param rst
   * @throws SQLException
   */
  public DataModel loadUserVO(UserData user, ResultSet rst) throws TMException, SQLException {
    if (!rst.next()) {
      return null;
    }

    if (user == null) {
      user = new UserData();
    }
    try {
      user.setId(rst.getLong(ID));
    } catch (FixedValueException e) {
      // TODO Auto-generated catch block
      logger.error(e.getMessage(), e);
    }
    user.setUserName(rst.getString(USER_NAME));
    user.setPassword(rst.getString(PASSWORD));
    user.setFirstName(rst.getString(FIRST_NAME));
    user.setMiddleName(rst.getString(MIDDLE_NAME));
    user.setLastName(rst.getString(LAST_NAME));
    user.setUserName(rst.getString(EMAIL_ID));
    user.setDob(rst.getString(DOB));
    user.setSex(rst.getInt(SEX));
    user.setAddressId(rst.getLong(ADDRESS_ID));
    user.setMaritalStatus(rst.getString(MARITAL_STATUS));
    user.setNationality(rst.getString(NATIONALITY));
    user.setImage(rst.getObject(IMAGE));
    user.setActive(rst.getBoolean(IS_ACTIVE));
    user.setActivationKey(rst.getString(ACTIVATION_KEY));
    return user;
  }
  private Map<FileChecksum, FileContent> createFileContents(ResultSet resultSet)
      throws SQLException {
    Map<FileChecksum, FileContent> fileContents = new HashMap<FileChecksum, FileContent>();
    FileChecksum currentFileChecksum = null;

    while (resultSet.next()) {
      FileChecksum fileChecksum = FileChecksum.parseFileChecksum(resultSet.getString("checksum"));
      FileContent fileContent = null;

      if (currentFileChecksum != null && currentFileChecksum.equals(fileChecksum)) {
        fileContent = fileContents.get(fileChecksum);
      } else {
        fileContent = new FileContent();

        fileContent.setChecksum(fileChecksum);
        fileContent.setSize(resultSet.getLong("size"));
      }

      ChunkChecksum chunkChecksum =
          ChunkChecksum.parseChunkChecksum(resultSet.getString("chunk_checksum"));
      fileContent.addChunk(chunkChecksum);

      fileContents.put(fileChecksum, fileContent);
      currentFileChecksum = fileChecksum;
    }

    return fileContents;
  }
  /** Web service operation */
  @WebMethod(operationName = "getUserByUID")
  public User getUserByUID(@WebParam(name = "uid") int uid) {
    User result = null;
    try {
      Statement stmt = conn.createStatement();
      String sql;

      sql = "SELECT * FROM user WHERE u_id = ?";
      PreparedStatement dbStatement = conn.prepareStatement(sql);
      dbStatement.setInt(1, uid);

      ResultSet rs = dbStatement.executeQuery();

      // Extract data from result set
      if (rs.next()) {
        result =
            new User(
                rs.getInt("u_id"),
                rs.getString("name"),
                rs.getString("email"),
                rs.getString("password"));
      } else {
        result = new User();
      }
      rs.close();
      stmt.close();
    } catch (SQLException ex) {
      Logger.getLogger(QuestionWS.class.getName()).log(Level.SEVERE, null, ex);
    }
    return result;
  }
  private static double getPrismPoint(
      String spatialcontext, String viewpoint, Database db, InputXML input, Point[] points)
      throws SQLException, ClientException, Exception {
    double prismPoint;
    if (input.getType().equals("PRISM")) {
      ResultSet result = db.getViewpoint(spatialcontext, viewpoint);
      if (!result.next()) {
        throw new ClientException(
            "viewpoint " + viewpoint + " in spatialcontext " + spatialcontext + " does not exist",
            404);
      }
      String filename = Config.getProperty("pointcloudpath") + result.getString("filename");
      Transformation trans = new Transformation(result.getString("pointcloud_trans"));
      trans.transform(new Transformation(result.getString("viewpoint_trans")));
      Transformation inv = trans.inverse();
      if (result.next()) {
        Config.warn(
            "more than one viewpoint in spatialcontext "
                + spatialcontext
                + " with name "
                + viewpoint
                + " in the database");
      }
      PlanarPolygon tmp = new PlanarPolygon(input.getAngles(), points);
      tmp.transform(inv);

      prismPoint = PTGInteraction.getPrismaPoint(tmp, filename);
      tmp.transform(trans);
    } else {
      prismPoint = 0;
    }
    return prismPoint;
  }
 void dodajpizzedozamowienia(int numer) {
   try {
     con =
         DriverManager.getConnection(
             "jdbc:derby://localhost:1527/BazaPizzerii", "pizzeria", "pizzeria");
     stmt2 = con.createStatement();
     res2 =
         stmt2.executeQuery(
             "select * from ZAMOWIENIE Z join SZCZ_O_PIZZY AS SP on Z.ID_ZAM=SP.ID_ZAM"
                 + " join MENU_PIZZA AS MP on SP.ID_PIZZY=MP.ID_PIZZY where Z.id_zam="
                 + numer);
     while (res2.next()) {
       int idszcz = res2.getInt("id_szcz_o_pizzy");
       int ilepizzy = res2.getInt("ile_sztuk_p");
       String pizza = ilepizzy + "";
       pizza += "x " + res2.getString("nazwa");
       pizza += " " + res2.getString("rozmiar");
       String ciasto = res2.getString("ciasto");
       if (ciasto.contains("grube")) {
         pizza += " na grubym cieście";
       } else if (ciasto.contains("cienkie")) {
         pizza += " na cienkim cieście";
       }
       pizza += "  " + dodajskladniki(idszcz, numer);
       model1.addElement(pizza);
     }
     lista.setModel(model1);
   } catch (SQLException ex) {
   }
 }
  public String retornaResp(int tipo, int id) throws SQLException {
    if (tipo == 0) {

      sql = "select descricao from grupo where idgrupo = ?";
      if (!FabricaConexoes.verificaConexao()) FabricaConexoes.getConexao();
      stm = FabricaConexoes.returnStatement(sql);
      stm.setInt(1, id);
      rs = FabricaConexoes.returnResult(stm);
      rs.next();
      return rs.getString("Descricao");

    } else if (tipo == 1) {
      sql = "select nome from usuario where idusuario = ?";
      if (!FabricaConexoes.verificaConexao()) FabricaConexoes.getConexao();
      stm = FabricaConexoes.returnStatement(sql);
      stm.setInt(1, id);
      rs = FabricaConexoes.returnResult(stm);
      rs.next();
      return rs.getString("nome");
    } else if (tipo == 2) {
      return "Destinado";
    } else {
      return "";
    }
  }
Beispiel #11
0
  public List<Employee> getEmployee() {
    connect();

    List<Employee> eList = new ArrayList<Employee>();

    try {

      String sql = "SELECT * FROM employee"; // SQL文を指定
      // クエリーを実行して結果セットを取得
      ResultSet rs = stmt.executeQuery(sql);
      // 検索された行数分ループ
      while (rs.next()) {
        Employee emp = new Employee();
        emp.setId(rs.getInt("id")); // classを取得
        emp.setName(rs.getString("name")); // nameを取得
        emp.setAge(rs.getInt("age")); // clubを取得
        emp.setAddress(rs.getString("address")); // addressを取得
        eList.add(emp);
      }
      close();
    } catch (SQLException e) {
      // TODO 自動生成された catch ブロック
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return eList;
  }
  public synchronized PlayerInventoryAccount getSellerAccount(ItemForSale ifs) {
    try {
      PreparedStatement getSellerAccount =
          this.con.prepareStatement(
              "SELECT id,uuid,username FROM "
                  + this.TBL_ACCOUNTS
                  + " WHERE id=(SELECT seller_id FROM "
                  + this.TBL_ITEMS
                  + " WHERE id=? LIMIT 1) LIMIT 1;");
      getSellerAccount.setInt(1, ifs.getDbID());

      ResultSet result = getSellerAccount.executeQuery();

      if (result.next()) {
        String username = result.getString("username");
        int dbID = result.getInt("id");
        UUID uuid = UUID.fromString(result.getString("uuid"));

        return new PlayerInventoryAccount(dbID, uuid, username);
      }
    } catch (SQLException ex) {
      Logger.getLogger(InventoryManager.class.getName()).log(Level.SEVERE, null, ex);
    }

    return null;
  }
  public void readDataBase(Connection connect) throws Exception {
    try {
      // Statements allow to issue SQL queries to the database
      statement = connect.createStatement();
      // Result set get the result of the SQL query
      rs =
          statement.executeQuery(
              "SELECT id, name, address, port, icon, realmflags, timezone, allowedSecurityLevel, population FROM realmlist WHERE (realmflags & 1) = 0 ORDER BY name");

      realms.clear();
      while (rs.next()) {

        Realm list = new Realm();
        list.setId(rs.getInt("id"));
        list.setName(rs.getString("Name"));
        list.setAddress(rs.getString("address"));
        list.setPort(rs.getShort("port"));
        list.setIcon(rs.getShort("icon"));
        list.setRealmflags(rs.getShort("realmflags"));
        list.setTimezone(rs.getShort("timezone"));
        list.setAllowedSecurityLevel(rs.getShort("allowedSecurityLevel"));
        list.setPopulation(rs.getFloat("population"));

        realms.add(list);
      }

    } catch (Exception e) {
      throw e;
    } finally {
      close();
    }
  }
Beispiel #14
0
  /**
   * Gets comments by module list id
   *
   * @param moduleListId
   * @return List DataModel.Comment
   */
  public List<Comment> getCommentsByModuleListId(String moduleListId) {

    List<Comment> comments = new ArrayList<Comment>();

    ResultSet result =
        db.preformQuery("SELECT * FROM Comments WHERE ModuleListID ='" + moduleListId + "'");

    try {
      while (result.next()) {
        Comment entry =
            new Comment(
                result.getInt("commentID"),
                result.getString("commentType"),
                result.getString("moduleListID"),
                result.getString("userID"),
                result.getString("commentDate"),
                result.getString("commentText"));

        comments.add(entry);
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR, "Problem with select from getCommentsByModuleListId user", e);
    }

    return comments;
  }
Beispiel #15
0
  /**
   * Gets messages from a user.
   *
   * @param user
   * @return List DataModel.Messages
   */
  public List<Messages> getMessagesFromUser(String user) {
    List<Messages> messages = new ArrayList<Messages>();

    ResultSet result = db.preformQuery("SELECT * FROM Messages WHERE userIDFrom='" + user + "'");

    try {
      while (result.next()) {
        Messages entry =
            new Messages(
                result.getString("messageID"),
                result.getString("messageDate"),
                result.getString("userIDfrom"),
                result.getString("UserIDTo"),
                result.getString("headLine"),
                result.getString("content"));

        messages.add(entry);
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR, "Problem with select from messages TO user", e);
    }

    return messages;
  }
Beispiel #16
0
  /**
   * Gets all the files that is delivered to the module. Module-id refers to a delivered task
   *
   * @param moduleId
   * @return List DataModel.ModuleFile
   */
  public List<ModuleFile> getModuleFiles(String moduleId) {
    ResultSet result =
        db.preformQuery(
            "SELECT * FROM "
                + Tables.MODULEDATEDELIVERY_TABLE
                + " WHERE moduleListID='"
                + moduleId
                + "';");

    List<ModuleFile> files = new ArrayList<ModuleFile>();

    try {
      while (result.next()) {
        ModuleFile file = new ModuleFile();
        file.setModuleFileId(result.getString("moduleFileID"));
        file.setModuleListId(result.getString("moduleListID"));
        file.setFile(result.getString("moduleFile"));

        files.add(file);
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR, "Problem with getting module files for " + moduleId, e);
    }

    return files;
  }
 /**
  * Gets the number of links from the specified ALIADA dataset to the specified target dataset.
  *
  * @param datasetId The dataset Identifier in the internal DB.
  * @param targetDataset The target dataset name.
  * @return the number of links.
  * @since 2.0
  */
 public int getNumLinksToExtDataset(final int datasetId, final String targetDataset) {
   int numLinks = 0;
   try {
     final Statement sta = getConnection().createStatement();
     String sql =
         "SELECT job.input_graph, subjob.num_links FROM subset, linksdiscovery_job_instances job,"
             + " linksdiscovery_subjob_instances subjob WHERE subset.datasetId="
             + datasetId
             + " AND job.input_graph=subset.graph_uri AND subjob.job_id=job.job_id"
             + " AND subjob.name='"
             + targetDataset
             +
             // Order the results to group together the links for the same graph
             // so that we only use the first row of them, as it is the latest linking
             // performed against that graph
             "' ORDER BY job.input_graph DESC,  subjob.end_date DESC";
     ResultSet resultSet = sta.executeQuery(sql);
     String prevGraph = "";
     while (resultSet.next()) {
       if (!prevGraph.equals(resultSet.getString("input_graph"))) {
         // Get only the latest number of links found.
         numLinks = numLinks + resultSet.getInt("num_links");
         prevGraph = resultSet.getString("input_graph");
       }
     }
     resultSet.close();
     sta.close();
   } catch (SQLException exception) {
     LOGGER.error(MessageCatalog._00024_DATA_ACCESS_FAILURE, exception);
   }
   return numLinks;
 }
Beispiel #18
0
  @Override
  public Article mapRow(ResultSet rs, int rowNum) throws SQLException {

    Article a = new Article();
    a.setId(rs.getInt("id"));
    a.setTitle(rs.getString("title"));

    Blob blob = rs.getBlob("content");
    int len = (int) blob.length();
    byte[] data = blob.getBytes(0, len);
    String content = new String(data);
    a.setContent(content);

    a.setCtime(rs.getTimestamp("ctime"));
    a.setUptime(rs.getTimestamp("uptime"));
    a.setTags(rs.getString("tags"));
    a.setCategory(rs.getString("category"));

    a.setAuthorId(rs.getInt("authorId"));
    a.setEditorId(rs.getInt("editorId"));
    a.setMediaId(rs.getInt("mediaId"));
    a.setPics(rs.getString("pics"));
    a.setExtra(rs.getString("extra"));

    return a;
  }
Beispiel #19
0
  public void datatable() {
    String KJ = jTextField1.getText();
    DefaultTableModel tbl = new DefaultTableModel();
    tbl.addColumn("No. Plat Polisi");
    tbl.addColumn("Jam Masuk");
    tbl.addColumn("Jam Kelaur");
    tbl.addColumn("Biaya");
    tbl.addColumn("ID Petugas");
    tbl.addColumn("Kode Kendaraan");
    jTable1.setModel(tbl);
    try {
      Statement statement = (Statement) conek.GetConnection().createStatement();
      ResultSet res = statement.executeQuery("select * from kkeluar where nplat LIKE'" + KJ + "%'");
      while (res.next()) {
        tbl.addRow(
            new Object[] {
              res.getString("nplat"),
              res.getString("jmask"),
              res.getString("jkluar"),
              res.getString("biaya"),
              res.getString("idpetugas"),
              res.getString("kodejenis")
            });
        jTable1.setModel(tbl);
      }

    } catch (Exception e) {
      JOptionPane.showMessageDialog(rootPane, "Salah");
    }
  }
  public static List<Message> getMessagesByUser(User user) {

    List<Message> messages = new ArrayList<Message>();
    ResultSet resultSet;
    Message message;
    String text, hash;
    int id;
    boolean valid = true;

    String sql = "SELECT * FROM mail WHERE userid = " + user.getId() + " ;";

    try {
      resultSet = getStatement().executeQuery(sql);

      while (resultSet.next()) {
        id = resultSet.getInt("mailid");
        text = resultSet.getString("message");
        hash = resultSet.getString("hash");
        message = Message.create(id, text, text.length(), hash, valid);
        messages.add(message);
      }

      getStatement().close();

    } catch (SQLException e) {
      e.printStackTrace(); // To change body of catch statement use File | Settings | File
      // Templates.
    }

    return messages;
  }
 private static Point[] anglesToFeature(
     String spatialcontext, String viewpoint, Angle[] angles, Database db)
     throws ClientException, SQLException, Exception {
   ResultSet result = db.getViewpoint(spatialcontext, viewpoint);
   if (!result.next()) {
     throw new ClientException(
         "viewpoint " + viewpoint + " in spatialcontext " + spatialcontext + " does not exist",
         404);
   }
   String filename = Config.getProperty("pointcloudpath") + result.getString("filename");
   Transformation ptrans = new Transformation(result.getString("pointcloud_trans"));
   Transformation vtrans = new Transformation(result.getString("viewpoint_trans"));
   if (result.next()) {
     Config.warn(
         "more than one viewpoint in spatialcontext "
             + spatialcontext
             + " with name "
             + viewpoint
             + " in the database");
   }
   Point[] points = null;
   try (Pointcloud pc = new Pointcloud(filename, ptrans)) {
     points = pc.getPoints(angles);
     pc.close();
   } catch (Exception e) {
     throw e;
   }
   for (Point point : points) {
     point.transform(vtrans);
   }
   return points;
 }
 public UserProfile mapRow(ResultSet rs, int numRow) throws SQLException {
   UserProfile userProfile = new UserProfile();
   userProfile.setUserProfileId(rs.getString("USER_PROFILE_ID"));
   userProfile.setUserName(rs.getString("NAME"));
   userProfile.setEmail(rs.getString("EMAIL"));
   return userProfile;
 }
  private static ElementBean getTrl(String sql) {
    PreparedStatement pstmt = DB.prepareStatement(sql, null);

    ElementBean retElementBean = null;
    try {
      ResultSet rs = pstmt.executeQuery();
      if (rs.next()) {
        retElementBean = new ElementBean();
        retElementBean.setColumnName(rs.getString(1));
        retElementBean.setName(rs.getString(2));
        retElementBean.setPrintName(rs.getString(3));
        retElementBean.setDescription(rs.getString(4));
        retElementBean.setHelp(rs.getString(5));
      } else {
        return null;
      }
      rs.close();
    } catch (Exception ex) {
      log.severe("Could retrieve element translation with sql: " + sql);
    } finally {
      try {
        pstmt.close();
      } catch (Exception ex) {
      }
    }

    return retElementBean;
  }
Beispiel #24
0
  public JobIniciado retornaUltimoLote(Connection conn, String job, int operacao)
      throws SQLException {

    String sql =
        " select job, operacao, tripulacao,recurso, max(data_fim) \n"
            + "from joblote where job = ? and operacao = ? \n"
            + "group by job, operacao, tripulacao, recurso ";

    PreparedStatement stmt = null;
    ResultSet rs = null;
    JobIniciado iniciado = null;

    stmt = conn.prepareStatement(sql);
    stmt.setString(1, job.trim().replace(".", ""));
    stmt.setInt(2, operacao);
    rs = stmt.executeQuery();

    if (rs.next()) {

      iniciado = new JobIniciado();
      iniciado.setJob(rs.getString(1));
      iniciado.setOperacao(rs.getInt(2));
      iniciado.setTripulacao(rs.getDouble(3));
      iniciado.setRecurso(rs.getString(4));
      Timestamp data = rs.getTimestamp(5);
      iniciado.setData(Validacoes.getDataHoraString(data));
    }

    return iniciado;
  }
Beispiel #25
0
 @Override
 public void columnsForTables(Table table, DatabaseMetaData dbmd) {
   try {
     rs = dbmd.getColumns(null, "%", table.getName(), null);
     ResultSet priamryKeyRs = dbmd.getPrimaryKeys(null, null, table.getName());
     String priamryKey = null;
     while (priamryKeyRs.next()) {
       priamryKey = priamryKeyRs.getString("COLUMN_NAME");
     }
     while (rs.next()) {
       Column column = new Column();
       String name = rs.getString("COLUMN_NAME");
       column.setName(name);
       column.setType(rs.getString("TYPE_NAME"));
       int columnSize = rs.getInt("COLUMN_SIZE");
       int nullable = rs.getInt("nullable");
       column.setNullable(nullable == 1);
       column.setDataSize(columnSize);
       if (column.getName().equals(priamryKey)) {
         column.setPrimaryKey(true);
       }
       table.addColumn(column);
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Beispiel #26
0
  private HashMap<String, String> getLoginInfo(
      String url, String db, String userName, String password) throws SQLException {
    Connection con = null;
    String driver = "com.mysql.jdbc.Driver";
    HashMap<String, String> info = new HashMap<String, String>();
    try {
      Class.forName(driver);
      con = DriverManager.getConnection(url + db, userName, password);
      String selectStatement = "SELECT userId,userName FROM Users";
      Statement st = con.createStatement();
      ResultSet linksRecords = st.executeQuery(selectStatement);

      while (linksRecords.next()) {
        info.put(linksRecords.getString("userId"), linksRecords.getString("userName"));
      }
      linksRecords.close();
    } catch (SQLException s) {
      // System.out.println("SQL statement is not executed!\n"+s.getMessage());
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      try {
        con.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return info;
  }
Beispiel #27
0
  public void updateScore(List<Player> players) {
    try {
      if (connection == null || players.size() <= 0) {
        return;
      }

      List<String> playersName = new ArrayList<String>();
      for (Player player : players) {
        playersName.add("'" + player.getName() + "'");
      }
      String arrs = join(playersName, ",");
      String strSql = "SELECT * FROM player WHERE name IN (" + arrs + ")";

      cacheScores.clear();

      Map<String, Object> map;
      Statement sql = connection.createStatement();

      ResultSet result = sql.executeQuery(strSql);
      while (result.next()) {
        map = new HashMap<String, Object>();
        map.put("kills", result.getInt("kills"));
        map.put("deaths", result.getInt("deaths"));
        map.put("mobs", result.getInt("mobs"));
        map.put("prefix", result.getString("prefix"));
        cacheScores.put(result.getString("name"), map);
      }
      result.close();

      sql.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 @Override
 public List<User> getAll() throws DAOException {
   String ALL_USERS = "SELECT * FROM users;";
   List<User> users = new ArrayList<>();
   Connection connection = null;
   try {
     connection = ConnectionHolder.getConnection();
     Statement statement = connection.createStatement();
     ResultSet rs = statement.executeQuery(ALL_USERS);
     while (rs.next()) {
       int k = 1;
       int id = rs.getInt(k++);
       String firstName = rs.getString(k++);
       String lastName = rs.getString(k++);
       String email = rs.getString(k++);
       String password = rs.getString(k++);
       User user = new User(firstName, lastName, email, password, " ");
       user.setId(id);
       users.add(user);
     }
   } catch (SQLException ex) {
     log.error("SQLException during answer delete query", ex);
     throw new DAOException(ex);
   }
   return users;
 }
Beispiel #29
0
  public static UserLoginResponse userLogIn(final UserLoginRequest userInfo)
      throws SQLException, IOException, PropertyVetoException, ClassNotFoundException {
    final String query = Query.SELECT_USER_DETAILS.toString();
    final Connection conn = DataSource.getInstance().getConnection();
    final PreparedStatement stmt = conn.prepareStatement(query);
    stmt.setString(1, userInfo.getUserId());

    ResultSet rs = stmt.executeQuery();
    if (!rs.next()) {
      conn.close();
      throw new SQLException("User ID " + userInfo.getUserId() + " does not exist.");
    } else {
      if (!rs.getString("password").equals(userInfo.getPassword())) {
        conn.close();
        throw new SQLException("Authentication problem.");
      }
      UserLoginResponse resp =
          new UserLoginResponse(
              "200",
              "Login Success.",
              userInfo.getUserId(),
              rs.getString("name"),
              rs.getString("password"),
              rs.getString("clickDelayInSeconds"),
              rs.getString("uploadIntervalInSeconds"));
      conn.close();
      return resp;
    }
  }
Beispiel #30
0
  /**
   * Gets links to one module
   *
   * @param moduleID
   * @return List DataModel.ModuleResourceLinks
   */
  public List<ModuleResorceLinks> getModuleLinks(String moduleID) {
    List<ModuleResorceLinks> links = new ArrayList<ModuleResorceLinks>();

    ResultSet result =
        db.preformQuery("SELECT * FROM ModuleResorceLinks WHERE moduleID = '" + moduleID + "';");

    try {

      while (result.next()) {
        ModuleResorceLinks link =
            new ModuleResorceLinks(
                result.getInt("moduleLinkID"),
                result.getString("moduleID"),
                result.getString("linkName"),
                result.getString("link"),
                result.getString("linkTags"));
        links.add(link);
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR,
          e.toString(),
          "Problem with getting ModuleResorceLinks for " + moduleID);
    }
    return links;
  }