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。