示例#1
0
  public void saveUser(User user) throws AtmDataException {
    Calendar now = Calendar.getInstance(); // Gets the current date and time.
    Date updateDate = new java.sql.Date(now.getTime().getTime());

    try {
      m_saveUserStatement.setLong(1, user.getUserId());
      m_saveUserStatement.setString(2, user.getFirstName());
      m_saveUserStatement.setString(3, user.getLastName());
      m_saveUserStatement.setDate(4, updateDate);
      m_saveUserStatement.executeUpdate();
    } catch (SQLException ex) {
      throw new AtmDataException(ex);
    }
  }
示例#2
0
  private static void testAddUser(DataAccess da) throws AtmDataException {
    trace("Test adding user ...");
    User user = new User(1, "FirstTest", "LastTest");
    da.saveUser(user);

    trace("User saved: " + user.toString());

    List<User> userList = da.getUsers();

    if (userList.size() > 0) {
      String msg = String.format("successful save: Count=%d", userList.size());
      trace(msg);
      dumpList(userList);
    } else {
      trace(" failed to save user");
    }

    trace("Test adding user complete");
  }
示例#3
0
 private static void dumpList(List<User> list) {
   for (User user : list) {
     trace(user.toString());
   }
 }