java程序远程访问Domino数据库简例

package kenny.remote;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.NotesException;
import lotus.domino.NotesFactory;
import lotus.domino.Session;
import lotus.domino.View;
/**
 * @author Kenny
 * example:java程序远程访问Domino服务器
 */
public class ConnectDomino {
 //要访问的Domino服务器域名,也可以用IP,默认的DIIOP端口是63148,若不知道端口,请询问管理员
 private final static String HOST = "oa.abc.com.cn:63148";
 //用户名必须是name.nsf中注册的用户名,当然如果服务器允许匿名访问,这可以不需要此用户名
 private final static String USERNAME = "admin";
 private final static String PASSWORD = "admin";
 public void getDominoDB(){
  Session session = null;
  Database db = null;
  View view = null;
  Document doc = null,docx = null;
  try{
   //建立连接会话,若匿名访问,用NotesFactory.createSession(HOST)即可
   session = NotesFactory.createSession(HOST, USERNAME, PASSWORD);
   db = session.getDatabase("SvrName", "DBName.nsf");
   view = db.getView("ViewName");
   doc = view.getFirstDocument();
   while(doc != null){
    //Process the Document doc
    System.out.println(doc.getCreated());
    //Then get the next document
    docx = view.getNextDocument(doc);
    //recycle the document we're done with,in the loop body,that's necessary
    if(doc != null) doc.recycle();
    doc = docx;
    if(docx != null) docx.recycle();
   }
  }catch(NotesException e){
   e.printStackTrace();
  }finally{
   try{//all of the domino objects must be recycle
    if(docx != null) docx.recycle();
    if(doc != null) doc.recycle();
    if(view != null) view.recycle();
    if(db != null) db.recycle();
    if(session != null) session.recycle();
   }catch(NotesException eRecycle){
    eRecycle.printStackTrace();
   }
  }
 }
}

    另外,java程序的类路径必须包含NCSO.jar,此包可以从安装了Domino服务器或者Domino Designer客户端软件的计算机上获得,具体路径为\Data\domino\java。

posted @ 2010-10-01 08:01  hannover  阅读(480)  评论(0编辑  收藏  举报