Working with EmbeddedScript

The EmbeddedScript class provides support for starting a scripting session, executing scripting commands, retrieving results, and ending the session using the Java™ programming language.

Modifier and Type / Method Description
void open() throws EmbeddedScriptException

Opens a connection to the command line processor.

EmbeddedScript script = new EmbeddedScript();
try
{
   script.open();
   ...
}
catch (EmbeddedScriptException e)
{
   ...
}
finally
{
   script.close();
}
void execute() throws EmbeddedScriptException

Executes a script command. Statements do not need to be terminated with semicolon (;) when executing commands using EmbeddedScript. If the command succeeds, the results can be accessed by calling getResult(). If the command fails, an exception is thrown.

EmbeddedScript script = new EmbeddedScript();

try
{
   script.open();
   script.execute(connect server username user1 password pass1);
   Result result = script.getResult();
   ...
}
catch (EmbeddedScriptException e)
{
 int resultCode = e.getResultCode();
 String message = e.getResultMessage();
}
finally
{
   script.close();
}
void close()

Closes from the command line processor session. Closing is required and ensures that the command line processor successfully disconnects from datastores and Access Server, if those connections are not closed using scripting commands.

EmbeddedScript script = new EmbeddedScript();

try
{
   script.open();
   ...
}
catch (EmbeddedScriptException e)
{
   ...
}
finally
{
   script.close();
}
Result getResult()

Returns the last result. Results can be printed to the console using result.display(System.out) or cast to a specific result type:

  • ResultNull
  • ResultStringKeyValues
  • ResultStringList
  • ResultStringTable
  • ResultStringValue
try
{
   script.execute(list datastores);
   Result result = script.getResult();
   if (result instanceof ResultStringTable)
   {
      ...
   }
}
catch (EmbeddedScriptException e)
{
   ...
}
int getResultCode()

Returns the result code for statement execution.

String getResultMessage()

Returns the last result message. The message may be null if the command executes successfully.

int getStatus()

Returns the status of the command as EmbeddedScript.SUCCESS or EmbeddedScript.FAILURE.

String getVerboseMessages()

If verbose is enabled, returns any messages that have been logged during command execution. To enable verbose mode, execute:

script.execute(set verbose);

The EmbeddedScriptException class provides access to the result error code and result error message

Header Header
int getResultCode()

Returns the result code for statement execution.

String getResultCodeAndMessage()

Returns a formatted result code and message.

String getResultMessage()

Returns the last result message. The message may be null if the command executes successfully.