Examples: Locating a database on a server or the local directory

This agent prints the file name and title of each database and template in the local directory.

import lotus.domino.*;
public class JavaAgent extends AgentBase {
  public void NotesMain() {
    try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();
      // (Your code goes here) 
      DbDirectory dir = session.getDbDirectory(null);
      String server = dir.getName();
      if (server.equals("")) server = "Local";
      System.out.println ("Database directory list on server"+
      server + "\n");
      System.out.println("***DATABASES***\n");
      Database tmpdb;
      Database db = dir.getFirstDatabase(DbDirectory.DATABASE);
      while (db != null) {
        String fn = db.getFileName();
        String title = db.getTitle();
        System.out.println(fn.toUpperCase() + " - " + title);
        tmpdb = dir.getNextDatabase();
        db.recycle();
        db = tmpdb; }
      System.out.println("\n***TEMPLATES***\n");
      db = dir.getFirstDatabase(DbDirectory.TEMPLATE);
      while (db != null) {
        String fn = db.getFileName();
        String title = db.getTitle();
        System.out.println(fn.toUpperCase() + " - " + title);
        tmpdb = dir.getNextDatabase();
        db.recycle();
        db = tmpdb; }
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}