Thursday 22 December 2011

Retrieve list of databases on Lotus Notes server

Retrieve list of databases on Lotus Notes server
This task use java to retrieve list of databases on Lotus Notes server.
Retrieve list of databases using DbDirectory
  1. Create listDatabase method as following
  2. Call listDatabase method as following
Call method
try {
    String idfile = "path to your id file";
    String password = "your password";
    String server = "your server, empty if local";
    NotesThread.sinitThread();
    Session s = NotesFactory.createSessionWithFullAccess();
    s.createRegistration().switchToID(idfile, password);
    List<Database> dblist = listDatabase(s, server);
    for (int i = 0; i < dblist.size(); i++) {
        Database db = dblist.get(i);
        logger.info(db.getTitle() + " | " + db.getFilePath());
        db.recycle();
    }
    s.recycle();
} catch (Exception e) {
    logger.info("", e);
}
    
listDatabase method
private List<Database> listDatabase(Session session, String server) throws Exception {
    List<Database> tag = new ArrayList<Database>();
    DbDirectory dir = session.getDbDirectory(server);
    Database db = dir.getFirstDatabase(DbDirectory.DATABASE);
    while (db != null) {
        tag.add(db);
        db = dir.getNextDatabase();
    }
    db = dir.getFirstDatabase(DbDirectory.TEMPLATE);
    while (db != null) {
        tag.add(db);
        db = dir.getNextDatabase();
    }
    return tag;
}
    

  Protected by Copyscape Online Copyright Protection

No comments:

Post a Comment