Examples: getDatabase method

  1. This agent gets a database and tests the resulting Database object with isOpen to ensure that the database exists and can be opened.
    import lotus.domino.*;
    
    public class JavaAgent extends AgentBase {
    
      public void NotesMain() {
    
        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();
    
          // (Your code goes here) 
          Database db = session.getDatabase("snapper", "names2");
          if (!db.isOpen())
            System.out.println("names2.nsf does not exist on snapper");
          else
            System.out.println("Title of names2.nsf: \"" + db.getTitle()+ "\"") ;
    
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. This agent gets a database, creating a Database object only if the database exists and can be opened. The agent tests to see if the Database object was created.
    import lotus.domino.*;
    
    public class JavaAgent extends AgentBase {
    
      public void NotesMain() {
    
        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();
    
          // (Your code goes here) 
          Database db = session.getDatabase("snapper", "names2", false);
          if (db == null)
            System.out.println("names2.nsf does not exist on snapper");
          else
            System.out.println("Title of names2.nsf: \"" + db.getTitle()+ "\"") ;
    
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }