예제 #1
0
 public void workerNameForCurrentWorker() throws Exception {
   userIdForCurrentUser();
   if (Global.user_id == 0) {
     return;
   }
   if (!newConnection()) {
     return;
   }
   try {
     /* PreparedStatement to issue SQL query */
     // Search worker using worker_id
     preparedStatement =
         connection.prepareStatement(
             "select last_name, first_name from workers where id = " + Global.worker_id);
     resultSet = preparedStatement.executeQuery();
     resultSet.first();
     String _worker_last_name = resultSet.getString("last_name");
     String _worker_first_name = resultSet.getString("first_name");
     Global.worker_name = _worker_last_name + ", " + _worker_first_name;
   } catch (Exception e) {
     throw e;
   } finally {
     closeDataObjects();
   }
 }
예제 #2
0
 public void readWorkers() throws Exception {
   try {
     if (!newConnection()) {
       return;
     }
     // PreparedStatement to issue SQL query
     preparedStatement = connection.prepareStatement("select * from workers");
     // SQL query's ResultSet with PreparedStatement
     resultSet = preparedStatement.executeQuery();
     LocalDate d = new LocalDate();
     LocalTime t = new LocalTime();
     System.out.println(Global.hostName + " - Running at " + d + " " + t + "\n");
     while (resultSet.next()) {
       // It is possible to get the columns via name
       // also possible to get the columns via the column number
       // which starts at 1
       // e.g. resultSet.getSTring(2);
       String lastName = resultSet.getString("last_name");
       String firstName = resultSet.getString("first_name");
       String workerCode = resultSet.getString("worker_code");
       Date createdAt = resultSet.getDate("created_at");
       System.out.println(
           "Worker: "
               + lastName
               + ", "
               + firstName
               + "\t ("
               + workerCode
               + ")\t Created at: "
               + createdAt);
       /*
        * System.out.println("Code: " + workerCode);
        * System.out.println("Created at: " + createdAt);
        */
     }
   } catch (Exception e) {
     throw e;
   } finally {
     closeDataObjects();
   }
 }
예제 #3
0
 public void readTimeRecordCodes() throws Exception {
   try {
     if (!newConnection()) {
       return;
     }
     // PreparedStatement to issue SQL query
     preparedStatement =
         connection.prepareStatement("select id, name from timerecord_codes order by id");
     // SQL query's ResultSet with PreparedStatement
     resultSet = preparedStatement.executeQuery();
     // Load codes list
     Global.codesList.clear();
     while (resultSet.next()) {
       Integer _id = resultSet.getInt("id");
       String _name = resultSet.getString("name");
       TimeRecordCode _code = new TimeRecordCode(_id, _name);
       Global.codesList.add(_code);
     }
   } catch (Exception e) {
     throw e;
   } finally {
     closeDataObjects();
   }
 }