<commit_before><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<chapter id="OpenConnection">
  <title>Connecting to a VDB through JDBC</title>
  <para>At this point you have deployed Federate Embedded and your VDB. Now it's time to connect the sample application
   to this VDB, issue SQL queries, and view the returned, integrated data. Note that
    this process is no different than connecting to any other JDBC source.</para>
  <sect1>
    <title>Stand-alone Java Application Deployment</title>
    <para>
      For a Java application to connect to a JDBC source, it needs a URL, user-id, and password. To
      connect to your VDB all you need is URL and any additional optional properties that you would like to set
      such as log file, number of threads etc. Currently the Federate Embedded is not associated with any user
      authentication system, so user-id and password are not required. The JDBC connection is supported through
      <emphasis>"com.metamatrix.jdbc.EmbeddedDriver"</emphasis>
      driver requires the URL syntax of
    </para>
    <para>
      <emphasis>jdbc:metamatrix:&lt;VDB-Name&gt;</emphasis>
    </para>
    <para/>
    <para>to connect to the VDB. You can add any additional optional properties at the end after the semi-colon(;) using name=value
      format. If multiple properties are defined, they should be separated additional semi-colons. For example</para>
    <para />
    <para>
      <emphasis>jdbc:metamatrix:&lt;VDB-Name&gt;;dqp.logFile=/home/query.log</emphasis>
    </para>
    <para />
    <para>
      You can use any of these <ulink url="/project/federate/url-properties"></ulink>optional connection properties
      in your URL. Here is sample code showing how to make JDBC connection.
    </para>
    <programlisting><![CDATA[
      public void execute() throws SQLException {
          String url = "jdbc:metamatrix:Accounts";
          String sql = "select firstname, lastname from customer";
          
          Class.forName("com.metamatrix.jdbc.EmbeddedDriver");
          
          Connection connection;
          try{
              connection = DriverManager.getConnection(url);
              Statement statement = connection.createStatement();
              ResultSet results = statement.executeQuery(sql);
              while(results.next()) {
                System.out.println(results.getString(1));
                System.out.println(results.getString(2));
                ...
              }
              results.close();
              statement.close();
          } catch (SQLException e){
              e.printStackTrace();
              throw e;
          } finally {
              try{
                connection.close();
              }catch(SQLException e1){
                // ignore
              }              
          }
      }      
    ]]></programlisting>
    <para>You can also use <emphasis>com.metamatrix.jdbc.EmbeddedDataSource</emphasis>
      to make connection in your Java application. For example, you can use following code fragment to make a 
      connection to the VDB and issuing the query exactly same as in the above example</para>
      <programlisting><![CDATA[
        EmbeddedDataSource ds = new EmbeddedDataSource(); 
        ds.setDatabaseName("Accounts");
        
        Connection connection = ds.getConnection();
        ...
      ]]></programlisting>
      <para>EmbeddedData source also provides an option to set optional parameters using the "set" methods on the 
       data source look. For all the allowable properties at the 
       <ulink url="/project/federate/datasource-properties">data source properties</ulink>.</para>       
  </sect1>
  <sect1>
  <title>Testing Your Federate Embedded Deployment</title>
  <para>The Federate Embedded installation includes a simple Java class which demonstrates JDBC access of the deployed VDB.
  To execute this demonstration, follow these steps:</para> 
  <orderedlist>
    <listitem><para>Ensure Derby is running</para></listitem>
    <listitem><para>Change to the /examples/portfolio directory within your Federate Embedded installation</para></listitem>
    <listitem><para>Execute the run script (either for Linux or Windows)</para></listitem>
  </orderedlist>
    <para>The sample query, "select * from CustomerAccount", queries the view model and, from that, queries the two underlying
    data sources: one relational, one file-based. All the sample Java class does is connect to the VDB, issue the query, 
    and print the results. Federate Embedded does the "heavy lifting". 
    (For the complete code used in this example, look in the "examples/portfolio" directory.)</para>
    <para>
    You are encouraged to experiment with queries that go beyond the simple "select * from CustomerAccount". Additionally,
    there is a sample Yahoo connector that returns stock market data. It can be used in place of the text file so the 
    market data is more timely. Go to the Federate Connector Sandbox projects for more information. 
   </para>
     
  <para>If your application is Web based application, you can also deploy Federate Embedded in application server 
  and treat it as any other JDBC source by creating a connection pool with the 
  <emphasis>com.metamatrix.jdbc.EmbeddedDataSource</emphasis> and assigning it a JNDI name. 
  Refer to <ulink url="/project/federate/deployments">deployment to application server</ulink> for more information</para>
  </sect1>   
</chapter><commit_msg>FEDERATE-12:Adding PaulN latest changes to the document<commit_after><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<chapter id="OpenConnection">
  <title>Connecting to a VDB through JDBC</title>
  <para>At this point you have deployed Federate Embedded and your VDB. Now it's time to connect the sample application
   to this VDB, issue SQL queries, and view the returned, integrated data. Note that
    this process is no different than connecting to any other JDBC source.</para>
  <sect1>
    <title>Stand-alone Java Application Deployment</title>
    <para>
      For a Java application to connect to a JDBC source, it needs a URL, user-id, and password. To
      connect to your VDB all you need is URL and any additional optional properties that you would like to set
      such as log file, number of threads etc. Currently the Federate Embedded is not associated with any user
      authentication system, so user-id and password are not required. The JDBC connection is supported through
      <emphasis>"com.metamatrix.jdbc.EmbeddedDriver"</emphasis>
      driver requires the URL syntax of
    </para>
    <para>
      <emphasis>jdbc:metamatrix:&lt;VDB-Name&gt;</emphasis>
    </para>
    <para/>
    <para>to connect to the VDB. You can add any additional optional properties at the end after the semi-colon(;) using name=value
      format. If multiple properties are defined, they should be separated additional semi-colons. For example</para>
    <para />
    <para>
      <emphasis>jdbc:metamatrix:&lt;VDB-Name&gt;;dqp.logFile=/home/query.log</emphasis>
    </para>
    <para />
    <para>
      You can use any of these <ulink url="/project/federate/url-properties"></ulink>optional connection properties
      in your URL. Here is sample code showing how to make JDBC connection.
    </para>
    <programlisting><![CDATA[
      public void execute() throws SQLException {
          String url = "jdbc:metamatrix:Accounts";
          String sql = "select firstname, lastname from customer";
          
          Class.forName("com.metamatrix.jdbc.EmbeddedDriver");
          
          Connection connection;
          try{
              connection = DriverManager.getConnection(url);
              Statement statement = connection.createStatement();
              ResultSet results = statement.executeQuery(sql);
              while(results.next()) {
                System.out.println(results.getString(1));
                System.out.println(results.getString(2));
                ...
              }
              results.close();
              statement.close();
          } catch (SQLException e){
              e.printStackTrace();
              throw e;
          } finally {
              try{
                connection.close();
              }catch(SQLException e1){
                // ignore
              }              
          }
      }      
    ]]></programlisting>
    <para>You can also use <emphasis>com.metamatrix.jdbc.EmbeddedDataSource</emphasis>
      to make connection in your Java application. For example, you can use following code fragment to make a 
      connection to the VDB and issuing the query exactly same as in the above example</para>
      <programlisting><![CDATA[
        EmbeddedDataSource ds = new EmbeddedDataSource(); 
        ds.setDatabaseName("Accounts");
        
        Connection connection = ds.getConnection();
        ...
      ]]></programlisting>
      <para>EmbeddedData source also provides an option to set optional parameters using the "set" methods on the 
       data source look. For all the allowable properties at the 
       <ulink url="/project/federate/datasource-properties">data source properties</ulink>.</para>       
  </sect1>
  <sect1>
  <title>Testing Your Federate Embedded Deployment</title>
  <para>The Federate Embedded installation includes a simple Java class which demonstrates JDBC access of the deployed VDB.
  To execute this demonstration, follow these steps:</para> 
  <orderedlist numeration="arabic">
    <listitem><para>Ensure Derby is running</para></listitem>
    <listitem><para>Change to the /examples/portfolio directory within your Federate Embedded installation</para></listitem>
    <listitem><para>Execute the run script (either for Linux or Windows)</para></listitem>
  </orderedlist>
    <para>The sample query, "select * from CustomerAccount", queries the view model and, from that, queries the two underlying
    data sources: one relational, one file-based. All the sample Java class does is connect to the VDB, issue the query, 
    and print the results. Federate Embedded does the "heavy lifting". 
    (For the complete code used in this example, look in the "examples/portfolio" directory.)</para>
    <para>
    You are encouraged to experiment with queries that go beyond the simple "select * from CustomerAccount". Additionally,
    there is a sample Yahoo connector that returns stock market data. It can be used in place of the text file so the 
    market data is more timely. Go to the Federate Connector Sandbox projects for more information. 
   </para>
     
  <para>If your application is Web based, you can also deploy Federate Embedded in an application server 
  and treat it as any other JDBC source by creating a connection pool with the 
  <emphasis>com.metamatrix.jdbc.EmbeddedDataSource</emphasis> and assigning it a JNDI name. 
  Refer to <ulink url="/project/federate/deployments">deployment to application server</ulink> for more information</para>
  </sect1>   
</chapter>
{'fraction_non_alphanumeric': 0.08737864077669903, 'fraction_numerical': 0.0026721296873608268, 'mean_word_length': 2.886465905157494, 'pattern_counts': {'":': 0, '<': 157, '<?xml version=': 2, '>': 157, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6746945', 'n_tokens_mistral': 3032, 'n_tokens_neox': 2847, 'n_words': 1132}