Examples: copyToDatabase method

This agent copies the documents in a view of one database to a newly created database.

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 = agentContext.getCurrentDatabase();
      Database newdb = db.createCopy(null, "archive");
      System.out.println("Archive created");
      View view = db.getView("By Category");
      Document doc = view.getFirstDocument();
      int count = 0;
      while (doc != null) {
        doc.copyToDatabase(newdb);
        count++;
        doc = view.getNextDocument(doc); }
      System.out.println(count + 
                 " documents copied to archive");
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}