Difference between revisions of "Standard Mode"

From BaseX Documentation
Jump to navigation Jump to search
m (→‎Example: moved comments inside the code)
Line 17: Line 17:
 
==Example==  
 
==Example==  
 
   
 
   
#Create a session object:<br/><pre class="brush:java">Session session = new Session("localhost", 1984, "admin", "admin");</pre>
+
<pre class="brush:java">
#Run the command in question and print the textual result:<br/><pre class="brush:java">print session.execute("info database");</pre>
+
// Create a session object:
#Close the session:<br/><pre class="brush:java">session.close();</pre>
+
Session session = new Session("localhost", 1984, "admin", "admin");
 +
 
 +
//Run the command in question and print the textual result:
 +
print session.execute("info database");
 +
 
 +
//Close the session:
 +
session.close();
 +
</pre>

Revision as of 23:40, 12 December 2010

In the standard mode, a database command can be sent to the server using the execute() function of the Session. This functions returns the whole result. With the info() function, you can request some information on your executed process. If an error occurs, an exception with the error message will be thrown.

Usage

The standard execution works as follows:

  1. Create a new session instance with hostname, port, username and password.
  2. Call the execute() function of the session with the database commands as argument.
  3. Receive the result of a successfully executed command. As an error occurs an exception is thrown.
  4. Continue using the client (back to 2.), or close the session.

Example

// Create a session object:
Session session = new Session("localhost", 1984, "admin", "admin");

//Run the command in question and print the textual result:
print session.execute("info database");

//Close the session:
session.close();