<?php require_once( dirname(dirname(dirname( __FILE__ ))) . '/wp-load.php' ); ?>
<!-- START of header -->
<?php get_header(); ?>
<!-- END of header -->

<!-- warapper -->

<div class="docs-content">
    <!-- START of page navigation -->
    <?php get_template_part( 'docs_navigation' ); ?>
    <!-- END of page navigation -->
    <!-- START of pusher -->
    <div class="docs-content-body">
        <div id="content" class="docs-content-body__inner">

                    
            <h1 class="title">5.1.5 Preparation: Connecting to GridDB</h1>
            <h2 id="overview">Overview</h2>
            <p>This section describes the connecting to and disconnecting from a GridDB server.</p>
            <p><br/></p>
            <h2 id="connection-to-the-griddb">Connecting to GridDB</h2>
            <p>In order to connect with the GridDB server, we use a Property class to set the connnection details which will be used by GridStoreFactory to open a connection. Refer to <a href="5-1-3_prepare-server.php">Environment (server)</a> on what these settings are configured as in your envrionment.</p>
            <strong>List.1 Connecting to a GridDB server</strong> (GridDBLogic.java)
            <pre class="prettyprint linenums:22">
            // Set the Connection parameter for GridDB
            Properties props=new Properties ();
            props.setProperty("host", "127.0.0.1");
            props.setProperty("port", "10001");
            props.setProperty("clusterName", "GSCLUSTER");
            props.setProperty("database", "public");
            props.setProperty("user", "admin");
            props.setProperty("password", "admin");
            GridStore store=GridStoreFactory.getInstance().getGridStore(props);
            </pre>
            <p>Parameters of GridDB connection are as follows.</p>
            <p>L.24: <code>host</code> specifies the destination host name or IP address (IPV4 only).<br>
            L.25: <code>port</code> specifies the destination port number.<br>
            L.26: <code>clusterName</code> specifies the destination cluster name.<br>
            L.27: <code>database</code> specifies the database name of the destination. This value is the default can be omitted is the &quot;public&quot;.<br>
            L.28: <code>user</code> Specifies the user name of GridDB server.<br>
            L.29: <code>password</code> specifies the password of GridDB server.</p>
            <p>For more information on the parameters other than the above, refer to the <a href="../GridDB_API_Reference.html">GridDB API Reference</a>.</p>
            <p><br/></p>
            <h3 id="cut-from-griddb">Cut from GridDB</h3>
            <p>After the application's GridDB tasks have completed, the connection should be closed.</p>
            <strong>List.2 cut from GridDB</strong>(CollectionCreate.java)
<pre class="prettyprint linenums">
GridStore store=null;
try {
    // Processing to GridDB
    (Snip)
} finally {
    // Close Connection
    if (store!=null) {
        store.close ();
    }
}
</pre>
            <p>L.8: Using close() within a try/finally block.</p>
            <p>The following classes have a <code>close()</code> method that can terminate the connection with GridDB.</p>
            <ul>
            <li><code>GridStoreFactory</code></li>
            <li><code>GridStore</code></li>
            <li><code>Container</code></li>
            <li><code>Query</code></li>
            <li><code>RowSet</code></li>
            </ul>
            <p><br/></p>
            <h3 id="source-code">Source code</h3>
            <p>Complete source code used in this sample can be downloaded here:</p>
            <p>Download: <a href="img/container-create-drop.zip">container-create-drop.zip</a></p>
        </div>
    </div>
</div>
</div>
</div>
<!-- / main -->

<?php get_footer(); ?>
