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).
- Start ODBC Data Source Administrator. To do this, in the Windows Run dialog box, enter:
%windir%\syswow64\odbcad32.exe
- In the ODBC Data Source Administrator, choose the System DSN tab, and then choose Add.
- In the Create New Data Source dialog box, choose NotesSQL ODBC Driver, and then choose Finish.
- Complete the NotesSQL ODBC Driver configuration dialog box.
- Download the Easysoft JDBC-ODBC Bridge.
- 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.
- In the JDBC-ODBC Bridge Web Administrator, in the Configuration page, turn on the MultiProcess option.
- 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
isdrive:\Program Files (x86)\Easysoft Limited\Easysoft JDBC-ODBC Bridge
. - 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); } } }
- In a Command Prompt window, add
EJOB.jar
to the JavaCLASSPATH
. For example:set CLASSPATH="%CLASSPATH%;C:\Program Files (x86)\Easysoft Limited\Easysoft JDBC-ODBC Bridge\Jars\EJOB.jar"
cd
to the directory whereConnectToNotes.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