3/27/2010

Implement a typical loop routine to the previous diiop sample

The most typical sample of Notes API would be open view, get one document and change/get item value.

I previously posted a simple sample code for the beginner of DIIOP technology and some would want to know how to implement a typical Notes routine as follows.



NABLoop.java
import lotus.domino.* ;

public class NABLoop 
{
 static String host = "xxx.xxxx.com" ; // server address
 static String cName = "notes admin" ; //username
 static String dbname = "names.nsf"; // database (e.g. mail\\hnagashi.nsf)
 static String password = "password" ;  // internet password

  public static void main(String args[]){
     try{
   Session s = NotesFactory.createSession(host,cName,password) ;
   Database db = s.getDatabase("", dbname );

 if(!db.isOpen()){
  db.open();
 }
   View view = db.getView("People");
     Document doc = view.getFirstDocument();
   Document temp = null;
   String title = db.getTitle();
   String uname = s.getUserName();
   
   System.out.println("Session User Name: " + uname );
   System.out.println("ServerName: " + db.getServer());
   System.out.println("Title: " + title);

 while (doc != null)
 {
  System.out.println("User Name: " + doc.getItemValueString("FullName"));
  temp = view.getNextDocument(doc); 
  doc.recycle();   
  doc = null;
  doc = temp;
}

        }catch(NotesException ne){
   System.out.println(ne.id + ne.text);
   ne.printStackTrace() ;
 }catch (Exception e){e.printStackTrace() ;}
  }
}
Hope it helps!

No comments:

Post a Comment