There are two primary ways to Access Domino database from a Java Application.
- Use Domino java APIs to connect to Domino Database over DIIOP
- Install Servlets over Domino Server to accept HTTP request
Prerequisites:-
The java program/component accessing the domino objects should be compiled with
compatible JDK/JRE version. For Domino 6.5 use jdk 1.4. Check compatibility for later
versions. For queries search on Notes.net.
The Classpath should have Notes.jar or NCSO.jar files
e.g.:-
set classpath=%classpath%;c:\lotus\domino\Notes.jar
or
set classpath=%classpath%;c:\lotus\domino\data\domino\java\NCSO.jar
depending on whether the machine hosting java component will access the domino
database locally(Machine will have lotus notes client installed) or remotely (over TCP/IP
network) using DIIOP protocol
Notes.jar, ncso.jar files supplies packages containing domino specific classes. These files
are supplied with the Domino client and server software respectively.
Code:-
The lotus.domino package has NotesFactory class which can be used to create new
domino session.
The local calls require that the NotesThread class manage threads. NotesThread extends
java.lang.Thread to include special initialization and termination code for Domino. You
have three options:
- Execute threads through inheritance
- Execute threads through the Runnable interface
- Execute threads through the static methods
Execute threads through inheritance
To execute threads through inheritance, extend NotesThread instead of Thread and
include a runNotes method instead of run. Start a NotesThread thread the same way as
TCS Public any other thread with the start method. This technique is easy to use and less error prone
than the static methods .
import lotus.domino.*; public class myClass extends NotesThread { public static void main(String argv[]) { myClass t = new myClass(); t.start(); } public void runNotes() { // entry point for Notes thread try { Session s = NotesFactory.createSession(); // Operational code goes here } catch (Exception e) { e.printStackTrace(); } } }
Execute threads through the Runnable interface
To execute threads through the Runnable interface, implement Runnable and include a
run method as you would for any class using threads. This technique can be used when
you cannot extend NotesThread because you're extending another class.
import lotus.domino.*; public class myClass implements Runnable { public static void main(String argv[]) { myClass t = new myClass(); NotesThread nt = new NotesThread((Runnable) t); nt.start(); } public void run() {// entry point for thread try { Session s = NotesFactory.createSession(); // Operational code goes here } catch (Exception e) { e.printStackTrace(); } } }
Execute threads through the static methods
To execute threads through the static methods, call sinitThread() to initialize a thread and
stermThread() to terminate the thread. Call stermThread() exactly one time for each call
to sinitThread(); putting stermThread in a "finally" block is recommended. The static
methods can be used when inheritance is not possible or when event-based threads need
fine control.
import lotus.domino.*; public class myClass { public static void main(String argv[]) { try { NotesThread.sinitThread(); // start thread Session s = NotesFactory.createSession(); // Operational code goes here } catch (Exception e) { e.printStackTrace(); } finally { NotesThread.stermThread(); // must terminate every thread } } }
Each thread of an application making local calls must initialize a NotesThread object.
This includes AWT threads that access the Domino Objects. Listener threads must use
the static methods because they cannot inherit from NotesThread.
The remote calls require that the createSession signature whose first parameter is a non-
empty string makes remote calls. The first parameter identifies the computer containing
the Domino server. For example:
Session s = NotesFactory.createSession("myhost.east.acme.com")
or
Session s = NotesFactory.createSession("myhost.east.acme.com:63148")
The machine hosting the java application/ component should have NCSO.jar in the
The machine hosting the java application/ component should have NCSO.jar in the
classpath.
for example:
set classpath := %classpath%;c:\lotus\domino\data\domino\java\NCSO.jar
The code would be similar e.g.
import lotus.domino.*; public class myClass { public static void main(String argv[]) { try { String host = "myhost.east.acme.com:63148"; Session s = NotesFactory.createSession(host); // Operational code goes here } catch (Exception e) { e.printStackTrace(); } } }
These piece of codes can be used in java application to access domino object. These
methods allow only unsecured connection.