Hi All,
I have an agent programmed in Java. The requirement is that from the current document I have to get the attached excel file and read the same to get the data from it.
The EmbeddedObject.extractFile method throws a notes exception; the java console message is as below-
NotesException: Notes error: A database handle to a remote database cannot be used by more than one thread. (c:\Gaurav.xls)
at lotus.domino.local.EmbeddedObject.NextractFile(Native Method)
at lotus.domino.local.EmbeddedObject.extractFile(Unknown Source)
at JavaAgent.NotesMain(JavaAgent.java:47)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(NotesThread.java:208)
Please tell me where I may be wrong or pour in with your suggestions.
The code is as below for your reference :
import lotus.domino.*;
import java.io.*;
import java.sql.*;
import java.util.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
String fileName = "";
String pathToStore = "";
try
{
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Database currDb = agentContext.getCurrentDatabase();
Document Doc = agentContext.getDocumentContext();
Connection c = null;
Statement stmnt = null;
DatabaseMetaData dbmetadata = null;
ResultSetMetaData rsmetadata = null;
ResultSet rsResponse = null;
ResultSet tableType = null;
String catalog = null;
int i = 0;
//String tables[] = {};
// get the attached file
if (Doc == null)
{
System.out.println("Doc null");
}
RichTextItem body = (RichTextItem)Doc.getFirstItem("Body");
Vector v = body.getEmbeddedObjects();
Enumeration e = v.elements();
while (e.hasMoreElements())
{
EmbeddedObject eo = (EmbeddedObject)e.nextElement();
if (eo.getType() == EmbeddedObject.EMBED_ATTACHMENT)
{
fileName = eo.getSource();
pathToStore = "c:\\" + fileName;
eo.extractFile(pathToStore);
} // if eo.getType
} // while e has more elements
} catch(Exception e) {
e.printStackTrace();
}
}
}