Difference between revisions of "Standard Mode"

From BaseX Documentation
Jump to navigation Jump to search
Line 6: Line 6:
 
exception with the error message will be thrown.</p>  
 
exception with the error message will be thrown.</p>  
 
   
 
   
<h2>Usage</h2>
+
==Usage==
 
   
 
   
 
<p>The standard execution works as follows:</p>  
 
<p>The standard execution works as follows:</p>  
 +
 +
#Create a new session instance with hostname, port, username and password.
 +
#Call the <code>execute()</code> function of the session with the [[Commands|database commands]] as argument.
 +
#Receive the result of a successfully executed command. As an error occurs an exception is thrown.
 +
#Continue using the client (back to 2.), or close the session.
 
   
 
   
<ol start="1">
+
==Example==
<li>Create a new session instance with hostname, port, username and password.</li>
 
<li>Call the <code>execute()</code> function of the session with the <a href="commands">database command</a> as argument.</li>
 
<li>Receive the result of a successfully executed command. As an error occurs an exception is thrown.</li>
 
<li>Continue using the client (back to 2.), or close the session.</li>
 
</ol>
 
 
   
 
   
<h2>Example</h2>
+
#Create a session object:<br/><pre class="brush:java">Session session = new Session("localhost", 1984, "admin", "admin")</pre>  
+
#Run the command in question and print the textual result:<br/><pre class="brush:java">print session.execute("info database")</pre>  
<ol start="1">
+
#Close the session:<br/><pre class="brush:java">session.close()</pre>
<li>Create a session object:<br/>  
 
    <code>Session session = new Session("localhost", 1984, "admin", "admin")</code></li>  
 
<li>Run the command in question and print the textual result:<br/>  
 
    <code>print session.execute("info database")</code></li>  
 
<li>Close the session:<br/>  
 
    <code>session.close()</code></li>
 
</ol>
 
[[Category:Wikify]]
 

Revision as of 21:00, 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

  1. Create a session object:
    Session session = new Session("localhost", 1984, "admin", "admin")
  2. Run the command in question and print the textual result:
    print session.execute("info database")
  3. Close the session:
    session.close()