Connecting to Lotus Notes from Java

Before you can connect your Java application to Lotus Notes by using the JDBC-ODBC Bridge, you need to configure a NotesSQL ODBC driver data source. An ODBC data source stores the connection details for the target database (for example, Notes) and the ODBC driver that is required to connect to it (for example, the NotesSQL ODBC driver).

Note We recommend that you install version 8.0 of the NotesSQL ODBC driver, which is fully ODBC compliant (albeit to an earlier ODBC specification than later versions of the driver, which are partially ODBC 3.5 compliant).

  1. Start ODBC Data Source Administrator. To do this, in the Windows Run dialog box, enter:
    %windir%\syswow64\odbcad32.exe
  2. In the ODBC Data Source Administrator, choose the System DSN tab, and then choose Add.
  3. In the Create New Data Source dialog box, choose NotesSQL ODBC Driver, and then choose Finish.
  4. Complete the NotesSQL ODBC Driver configuration dialog box.
  5. Download the Easysoft JDBC-ODBC Bridge.
  6. Install and license the Easysoft JDBC-ODBC Bridge on the machine where you created the data source.

    For installation instructions, refer to the Easysoft JDBC-ODBC Bridge documentation.

  7. In the JDBC-ODBC Bridge Web Administrator, in the Configuration page, turn on the MultiProcess option.
  8. Copy EJOB.jar to a machine where you have a Java Development Kit installed.

    If the Easysoft JDBC-ODBC Bridge is already installed on this machine, skip this step.

    EJOB.jar is installed in the following location on the machine where you install the Easysoft JDBC-ODBC Bridge:

    easysoft_install\Jars

    The default location for easysoft_install is drive:\Program Files (x86)\Easysoft Limited\Easysoft JDBC-ODBC Bridge.

  9. Add this Java code to a file named ConnectToNotes.java:
    import easysoft.sql.*;
    import java.sql.*;
    import java.util.Calendar;
    import java.util.Date;
    
    
    public class ConnectToNotes {
    
      public static void main(String[] args) throws Exception {
    
            String[] szTableTypes;
            szTableTypes = new String[100];
    
            String[] szTableNames;
            szTableNames = new String[1000];
    
            int[]  szTypeCount;
            szTypeCount = new int[100];
    
            int intTableTypes;
    
        try {
    
          easysoft.sql.jobDriver driver = (easysoft.sql.jobDriver)Class.forName("easysoft.sql.jobDriver").newInstance();
    
          String jobUrl= "jdbc:easysoft://localhost/My32bitNotesSQLSystemDSN:logonuser=mywindowsuser:logonpassword=mywindowspassword";
          Connection con = DriverManager.getConnection(jobUrl, "mynotesuser", "mynotespassword");
          System.out.println(" ");
          System.out.println("------------------ Method Summary ------------------");
          try {
              int i;
              boolean bl;
              String st;
    
              DatabaseMetaData dbMD = null;
              dbMD = con.getMetaData();
    
    
    //------------------------------------------------------------------------
              try {
                  ResultSet rt = dbMD.getTableTypes();
                  intTableTypes=0;
                  st="";
                  while (rt.next()) {
                      szTableTypes[intTableTypes]=rt.getString(1);
                      intTableTypes++;
                  }
                  for (i=0; i<intTableTypes; i++)
                  {
                      st=st + szTableTypes[i] + "; ";
                  }
                  System.out.println("Table types (" + intTableTypes + ") : "+ st );
    
                  // Go get the tables e.t.c.
    
                  try {
                      int x;
                      ResultSet rs = dbMD.getTables( null, null, "%", null );
                      while (rs.next()) {
                          for (x=0; x<intTableTypes; x++)
                          {
                              System.out.println("TABLE_CAT : " + rs.getString(1));
                              System.out.println("TABLE_SCHEM : " + rs.getString(2));
                              System.out.println("TABLE_NAME : " + rs.getString(3));
                              System.out.println("TABLE_TYPE : " + rs.getString(4));
                              System.out.println("REMARKS  : " + rs.getString(5));
     System.out.println("------------------------------------------------------");
                          }
                      }
                  } catch (Exception e) {
                      System.out.println("getTables error : " + e );
                  }
    
              } catch (Exception e) {
                  System.out.println("getTableTypes error : " + e );
              }
     //------------------------------------------------------------------------
          }  catch(Exception e) {
              System.out.println("db Meta Data exception: " + e);
              e.printStackTrace();
          }
        } catch(Exception e){
                System.out.println("Java code error : " + e);
        }
        }
    } 
  10. In a Command Prompt window, add EJOB.jar to the Java CLASSPATH. For example:
    set CLASSPATH="%CLASSPATH%;C:\Program Files (x86)\Easysoft Limited\Easysoft JDBC-ODBC Bridge\Jars\EJOB.jar"
  11. cd to the directory where ConnectToNotes.java is located, and compile and run the Java file. For example:
    "C:\Program Files\Java\jdk1.8.0_144\bin\javac.exe" ConnectToNotes.java
    java ConnectToNotes