Open Lotus Notes database
This task use java to open Lotus Notes database.
Open Lotus Notes database using DbDirectory
- Create openDatabase method as following
- Call openDatabase method as following
1 | try { |
2 | String idfile = "path to your id file"; |
3 | String password = "your password"; |
4 | // <server>!!<filepath> | <filepath> |
5 | String filename = "path to database file"; |
6 | NotesThread.sinitThread(); |
7 | Session s = NotesFactory.createSessionWithFullAccess(); |
8 | s.createRegistration().switchToID(idfile, password); |
9 | Database d = openDatabase(s, filename); |
10 | logger.info(d.getTitle() + " | " + d.getFilePath()); |
11 | d.recycle(); |
12 | s.recycle(); |
13 | } catch (Exception e) { |
14 | logger.info("", e); |
15 | } |
try { String idfile = "path to your id file"; String password = "your password"; // <server>!!<filepath> | <filepath> String filename = "path to database file"; NotesThread.sinitThread(); Session s = NotesFactory.createSessionWithFullAccess(); s.createRegistration().switchToID(idfile, password); Database d = openDatabase(s, filename); logger.info(d.getTitle() + " | " + d.getFilePath()); d.recycle(); s.recycle(); } catch (Exception e) { logger.info("", e); }
1 | private Database openDatabase(Session session, String filename) throws Exception { |
2 | int pos = filename.indexOf("!!"); |
3 | Database tag = null; |
4 | if (pos < 0) { |
5 | DbDirectory dir = session.getDbDirectory(""); |
6 | tag = dir.openDatabase(filename); |
7 | } else { |
8 | String server = filename.substring(0, pos); |
9 | String path = filename.substring(pos + 2, filename.length()); |
10 | DbDirectory dir = session.getDbDirectory(server); |
11 | tag = dir.openDatabase(path); |
12 | } |
13 | return tag; |
14 | } |
private Database openDatabase(Session session, String filename) throws Exception { int pos = filename.indexOf("!!"); Database tag = null; if (pos < 0) { DbDirectory dir = session.getDbDirectory(""); tag = dir.openDatabase(filename); } else { String server = filename.substring(0, pos); String path = filename.substring(pos + 2, filename.length()); DbDirectory dir = session.getDbDirectory(server); tag = dir.openDatabase(path); } return tag; }
No comments:
Post a Comment