<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to you under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!DOCTYPE faqs PUBLIC "-//APACHE//DTD FAQ V2.0//EN" "http://forrest.apache.org/dtd/faq-v20.dtd">


<faqs>
   <title>Frequently Asked Questions</title>

  <faqsection id="legal">
    <title>Legal</title>
    <faq id="derby_license">
      <question>
        What License is Derby under? (Quick Answer: ASL 2.0)
      </question>
      <answer>
        <p> Derby is available under the 
            <a href="license.html">Apache License, Version 2.0.</a>
        </p>
      </answer>
    </faq>
    <faq id="derby_icla">
      <question>
        Who needs to file an Individual Contributor License Agreement (ICLA)?
      </question>
      <answer>
        <p>
        The ASF <em>desires</em> contributors to submit an ICLA, but
        <em>requires</em> committers to do so.
        (See the "Contributor License Agreements" section on the
        <a href="http://www.apache.org/licenses/">Licenses</a> page.)
        Contributors who are not committers are in a somewhat fuzzy spot.
        Small fixes posted to Jira probably don't require an ICLA,
        especially since Jira includes an upload option to "Grant license
        to ASF for inclusion in ASF works (as per the
        <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache
        Software License</a>)".
        However, if you make a large contribution, or many contributions, 
        a Derby committer will likely ask you to submit an ICLA.
        </p>
      </answer>
    </faq>
  </faqsection>
  <faqsection id="general">
    <title>General</title>
    <faq id="faq_add">
      <question>
        How can I add a new entry to the Derby FAQ?
      </question>
      <answer>
        <p> We welcome additions!
        Please add your new entry to 
        <a href="http://issues.apache.org/jira/browse/DERBY-232">DERBY-232</a>.
        All you need is to create a 
        <a href="http://issues.apache.org">Jira id</a>
         if you don't already have one.
        </p>
      </answer>
    </faq>
    <faq id="site_search">
      <question>
        How do I search the Derby site?
      </question>
      <answer>
        <p> The left-hand menu on the Derby web site
           includes a search box that searches the
           entire db.apache.org web site; 
           so, that includes Derby and the other Apache DB Project sub-projects.
        </p>
        <p>If you want to search all of apache.org, the 
           <a href="http://www.apache.org/">ASF home page</a> has a search
           box for all of apache.org.
        </p>
        <p>
           If you want to restrict a search to a subset of the Derby site,
           for example to just the Derby manuals,
           one way to do that is to use a
           <a href="http://www.google.com">www.google.com</a>
            <a href="http://www.google.com/help/refinesearch.html">domain 
           search</a>.  
           For example, the search string below looks for all references
           to "create table" in the 10.13 documentation set:
        </p>
<source>
"create table" site:db.apache.org/derby/docs/10.13
</source>

      </answer>
    </faq>
  </faqsection>

  <faqsection id="developers">

    <title>Developing Derby</title>

    <faq id="derby_source">
      <question>
        Where is the Derby source code?
      </question>
      <answer>
        <p> The
	<a href="dev/derby_source.html">Apache Derby: Source Code</a> page
	provides instructions for checking out the Derby source code
	from the SVN repository at Apache.
	You can also use the
	<a href="http://www.apache.org/dev/version-control.html">Apache ViewCVS</a> 
	interface to view Derby source code using your web browser.
        </p>
        <p>
        Information about document source for the Derby manuals is covered 
        in the 
        <a href="manuals/dita.html">Apache Derby: DITA-sourced documentation</a>
        page.
        </p>
        <p>
        Information about web site source is covered in the
        <a href="papers/derby_web.html">Apache Derby Web Site</a> page.
        </p>

      </answer>
    </faq>

    <faq id="derby_internals">

      <question>
        Where can I read about Derby internals?
      </question>

      <answer>
        <p> The
	<a href="papers/index.html#Derby+Engine">Derby Engine</a>
        papers and the
        <a href="https://cwiki.apache.org/confluence/display/DERBY/HowItWorks">HowItWorks</a>
        Wiki page are good starting points.
	Also browse the
	<a href="derby_mail.html">derby-dev@db.apache.org</a>
	mail list and post any questions you have.
        </p>
      </answer>

    </faq>

    <faq id="derby_issues">
      <question>
        Where are Apache Derby bugs logged?
      </question>
      <answer>
        <p>
	Apache Derby uses 
	<a href="DerbyBugGuidelines.html">Apache's Jira issue 
	tracker</a> to track bugs.
	</p>
      </answer>
    </faq>

    <faq id="derby_update">
      <question>
        Who can create a new Apache Derby issue?
      </question>
      <answer>
        <p>
        Anyone can browse Apache Derby issues. 
        To log new issues, 
	see the <a href="DerbyBugGuidelines.html">tips</a> page,
	which describes how to create a userid for yourself and how
	to log useful bugs.
        To update existing issues, email your Jira userid to 
        <a href="derby_mail.html">derby-dev@db.apache.org</a> and
         request that it be added to the derby-developers Jira list.
	</p>
      </answer>
    </faq>
    <faq id="derby_eclipse">
      <question>
        How do you build Derby using Eclipse or Netbeans?
      </question>
      <answer>
	<p>See the Eclipse and Netbeans instructions on the 
        <a href="https://cwiki.apache.org/confluence/display/DERBY/BuildingDerby">BuildingDerby</a>
        Wiki page.
	</p>
      </answer>
    </faq>
    <faq id="derby_am">
      <question>
       What does the "am" in org.apache.derby.client.am mean?
      </question>
      <answer>
	<p>AM means "Abstract Machine". 
           The code in the client.am directory implements non-public JDBC
           interfaces that are
         <a href="http://mail-archives.apache.org/mod_mbox/db-derby-dev/200602.mbox/%3c43F4E9B5.5000708@Sourcery.Org%3e">independent of any specific protocol</a>.
	</p>
      </answer>
    </faq>
  </faqsection>

  <faqsection id="users_getstart">
    <title>Using Derby: Getting Started</title>

    <faq id="derby_ask">
      <question>
        Where can I ask questions about how to use Derby?
      </question>
      <answer>
        <p>
        Please post questions about how to use Derby to the
        <a href="derby_mail.html">derby-user@db.apache.org</a> mail list.
        Sometimes you might receive a response that refers you 
        to documentation, to a page on the Derby web site, or to another
        post on the mail list.
        Please don't be offended! 
        We are constantly working to improve the available documentation.
        And if the referenced post/page/documentation doesn't help, 
        feel free to ask for more help.
        </p>
      </answer>
    </faq>

    <faq id="derby_jar">
      <question>
        Where can I download the Derby jar files?
      </question>
      <answer>
        <p>
        You can download the Derby jar files 
	from the <a href="derby_downloads.html">Derby Downloads</a> page.
	</p>
      </answer>
    </faq>

    <faq id="where_are_docs">
      <question>
      Where can I find the Derby documentation?
      </question>
      <answer>
      <p>
      Derby documentation is available in PDF and HTML format from
<a href="manuals/index.html">http://db.apache.org/derby/manuals/</a>.
      </p>
      </answer>
    </faq>
    <faq id="pda">
      <question>
      Can you run Derby on small devices?
      </question>
      <answer>
      <p>
      Starting in 10.1, Derby added support for
      J2ME/CDC/Foundation with JSR169 as the JDBC api. 
      For more information, see the 
<a href="http://db.apache.org/derby/docs/10.7/ref/rrefjdbcjsr169.html">Reference
      Guide</a>. Starting with 10.11, Derby added support for running on the small Java 8 compact profile 2 platform.
      </p>
      </answer>
    </faq>
    <faq id="derby_javax">
      <question>
      Can I use Derby on Java release X?
      </question>
      <answer>
      <p>
        See the <a href="derby_downloads.html">Derby Downloads</a> page
        for the compatibility between Derby and Java versions.
      </p>
      </answer>
    </faq>

    <faq id="in_memory">
      <question>
      Does Derby have a mode that causes it to run entirely in memory?
      </question>
      <answer>
      <p>
      Of course! For more information,
      start <a href="https://cwiki.apache.org/confluence/display/DERBY/InMemoryBackEndPrimer">
          here</a>.
      </p>
      </answer>
    </faq>

    <faq id="derby_gui">
      <question>
      Does Derby have a GUI?
      </question>
      <answer>
      <p>
      No, Derby does not include a GUI. However,
      the web site includes a writeup on how to use
      <a href="integrate/SQuirreL_Derby.html">SQuirreL SQL</a>
      with Derby, and the
      <a href="https://cwiki.apache.org/confluence/display/DERBY/UsesOfDerby">UsesOfDerby</a>
      Wiki page list other GUIs that work with Derby.
      </p>
      </answer>
    </faq>
    <faq id="db_name">
      <question>
      How do you specify database location?
      </question>
      <answer>
      <p>
      You can specify a
      database name using an absolute or relative path.
      Details are in the
      <a href="http://db.apache.org/derby/docs/10.13/devguide/cdevdvlp34964.html">Developer's Guide</a>
      and helpful tips are on the
      <a href="https://cwiki.apache.org/confluence/display/DERBY/DatabaseNamesRelativeAbsolute">Derby
      Wiki</a>.
      </p>
      </answer>
    </faq>
    <faq id="win_service">
      <question>
      Can you run Derby as a Windows service?
      </question>
      <answer>
      <p>
      The <a href="https://cwiki.apache.org/confluence/display/DERBY/DerbyWindowsService">Derby
      Wiki</a> provides pointers to information on how to run Derby as a
      Windows service.
      </p>
      </answer>
    </faq>
    <faq id="derby_version">
      <question>
      How do I find out which version of Derby I am using? 
      </question>
      <answer>
      <p>
      You can use the sysinfo tool or the JDBC API to get version 
      information from your Derby installation. See the 
      <a href="https://cwiki.apache.org/confluence/display/DERBY/VersionInfo">VersionInfo 
      wiki page</a> for more details. 
      </p>
      </answer>
    </faq>

  </faqsection>

  <faqsection id="users_sql">
    <title>Using Derby: SQL</title>

    <faq id="null_args">
      <question>
      Why can't my SQL function/procedure pass a NULL INTEGER?
      </question>
      <answer>
      <p>
      Either declare the function with
      RETURNS NULL ON NULL INPUT
      or define the Java method signature in the external name clause. See the
      <a href="http://mail-archives.apache.org/mod_mbox/db-derby-user/200602.mbox/%3c4404E53D.1050605@apache.org%3e">"Create function problem"</a>
      derby-user mail list topic.
      </p>
      </answer>
    </faq>

    <faq id="limit">
      <question>
      Does Derby support a LIMIT command? 
      </question>
      <answer>
      <p>
          Derby does not support the LIMIT syntax. However, Derby 10.4
          added the <a href="http://db.apache.org/derby/docs/10.13/ref/rreffuncrownumber.html">ROW_NUMBER function</a>
          and Derby 10.7 added the
          <a href="http://db.apache.org/derby/docs/10.13/ref/rrefsqljoffsetfetch.html">OFFSET and FETCH clauses</a>.
          </p><p>
      Derby also supports limiting the number of rows returned by a query through
      <a href="http://mail-archives.apache.org/mod_mbox/db-derby-dev/200411.mbox/%3c41A95632.3010301@debrunners.com%3e">JDBC</a>. For example, to fetch the first 5 rows of a large table:
      </p>
      <!-- Using <code> and <br/> tags etc. as a workaround for including 
           multi-line formatted code examples, since Forrest's XML 
           validation fails when using other HTML tags (such as <pre>) in 
           this DTD element.
      -->
      <p>
      <code>Statement stmt = con.createStatement();</code><br/>
      <code>stmt.setMaxRows(5);</code><br/>
      <code>ResultSet rs = stmt.executeQuery("SELECT * FROM myLargeTable");</code><br/>
      </p>
      <p>
      Some related tuning tips are available in 
      <a href="http://www.onjava.com/pub/a/onjava/2007/01/31/tuning-derby.html?page=1">this 
      external article</a>.
      </p>
      <p>
      Starting with the 10.4.1.3 release Derby also supports limiting the number of
      rows using the <code>ROW_NUMBER</code> function. 
      </p>
      <p>
      For example, to fetch the first 5
      rows of a large table:
      </p>
      <p>
      <code>SELECT * FROM (</code><br/>
      &nbsp;&nbsp;&nbsp;&nbsp;<code>SELECT ROW_NUMBER() OVER() AS rownum, myLargeTable.*</code><br/>
      &nbsp;&nbsp;&nbsp;&nbsp;<code>FROM myLargeTable</code><br/>
      <code>) AS tmp</code><br/>
      <code>WHERE rownum &lt;= 5;</code><br/>
      </p>
      <p>
      The <code>ROW_NUMBER</code> function can also be used to select a 
      limited number of rows starting with an offset, for example:
      </p>
      <p>
      <code>SELECT * FROM (</code><br/>
      &nbsp;&nbsp;&nbsp;&nbsp;<code>SELECT ROW_NUMBER() OVER() AS rownum, myLargeTable.*</code><br/>
      &nbsp;&nbsp;&nbsp;&nbsp;<code>FROM myLargeTable</code><br/>
      <code>) AS tmp</code><br/>
      <code>WHERE rownum &gt; 200000 AND rownum &lt;= 200005;</code><br/>
      </p>
      <p>
      For more information, refer to the ROW_NUMBER built-in function in 
      the Derby Reference Manual (available from the 
      <a href="manuals/index.html">Documentation page</a>). Development 
      notes are available on the 
      <a href="https://cwiki.apache.org/confluence/display/DERBY/OLAPRowNumber">OLAPRowNumber 
      wiki page</a>.
      </p>
      <p>
      The <code>LIMIT</code> keyword is not defined in the SQL standard, 
      and is currently not supported.
      </p>
      </answer>
    </faq>
    <faq id="schema_exist">
      <question>
      Why do I get the error 'schema does not exist'?
      </question>
      <answer>
      <p>
      The current schema for any connection defaults to a schema corresponding
      to the user name. If no user name is supplied then the user name (and
      hence current schema) defaults to APP.
      </p>

      <p>
      However even though the current schema is set to the user name, that
      schema may not exist. A schema is only created by CREATE SCHEMA or
      creating an object (table etc.) in that schema (this is implicit schema
      creation).
      </p>

      <p>
      The one exception to this is the APP schema, which is always created,
      though applications should not depend on that.
      </p>

      <p>
      So you will see the schema not exists error if your application tries to
      access the current schema before any objects have been created in it.
      Possibilities are you try to perform a DROP TABLE before creating it, or
      try to SELECT from a table to see if it should be created or not, or
      when there is a problem with the sql for the very first object you try
      to create in a particular schema and no explicit CREATE SCHEMA was issued.
      </p>
      </answer>
    </faq>
    <faq id="debug_lock_timeout">
      <question>
      I get a lock timeout error. How do I debug this?
      </question>
      <answer>
      <p>
      To debug lock timeout errors, set 
      <code>derby.locks.monitor=true</code>
      and <code>derby.locks.deadlockTrace=true</code> in 
      <code>derby.properties</code>. 
      This will print the lock table information to the derby.log 
      when the timeout happens. 
      If you also set 
      <code>derby.language.logStatementText=true</code>,
      then all the statements executed on the system will be written 
      out to the <code>derby.log</code>.
      Statement information also includes the transaction id on 
      which the statement is being executed. 
      You can use the transaction id 
      holding the lock in the lock table dump
      to do a reverse search for the transaction id in
      <code>derby.log</code>,
      making it possible 
      to narrow down which statements may be holding the locks.
      </p>
      <p>Further information is available on the 
      <a href="https://cwiki.apache.org/confluence/display/DERBY/LockDebugging">LockDebugging</a>
      wiki page.
      </p>
      </answer>
    </faq>
    <faq id="identity">
      <question>
      Can Derby generate unique identifiers like sequences?
      </question>
      <answer>
      <p>
        SEQUENCE support was added to Derby in release 10.6.
      </p>
      <p>
        Also, Derby supports generated "identity" columns; examples are in
        the 
        <a href="http://db.apache.org/derby/docs/10.13/ref/rrefsqlj37836.html">Reference Guide</a>.
        The
        <a href="http://db.apache.org/derby/docs/10.13/ref/rrefidentityvallocal.html#rrefidentityvallocal">IDENTITY_VAL_LOCAL</a>
        function returns the most recently assigned number.
      </p>
      </answer>
    </faq>
  </faqsection>
  <faqsection id="users_client">
    <title>Using Derby: Client Programming</title>
    <faq id="clientserv">
      <question>
      Can you use Derby for client-server applications?
      </question>
      <answer>
      <p>
      Yes, you can use derby for client-server applications.
      Starting in 10.1 Derby included the
      <a href="http://db.apache.org/derby/docs/10.13/adminguide/cadminappsclient.html">Derby Network Client jdbc driver</a>.
      The <a href="https://cwiki.apache.org/confluence/display/DERBY/UsesOfDerby">UsesOfDerby</a>
      Wiki pages lists additional drivers, including
      <a href="http://c-jdbc.objectweb.org/">C-JDBC</a>
      and the
      <a href="http://www.ibm.com/developerworks/db2/downloads/jcc/">IBM
      DB2 JDBC Universal Driver</a>.
      </p>
      </answer>
    </faq>
    <faq id="netclient">
      <question>
      Does Derby include a client-server ("network") jdbc driver?
      </question>
      <answer>
      <p>
      Yes, Apache Derby has a JDBC driver
      that works with the Derby Network Server.
      It is called the
      <a href="http://db.apache.org/derby/docs/10.13/adminguide/cadminappsclient.html">Derby Network Client</a>
      and it became available starting with Derby 10.1.
      </p>
      </answer>
    </faq>
    <faq id="db2_jcc_errors">
      <question>
      How can I get the message text for an error using the DB2 JDBC
      Universal Driver?
      </question>
      <answer>
      <p>
      Set the connection attribute 
      <code>retrieveMessagesFromServerOnGetMessage=true</code>.
      For details, see the 
      <a href="http://mail-archives.apache.org/mod_mbox/db-derby-dev/200409.mbox/%3c4138B3C1.5090008@Sourcery.Org%3e">"Error Messages with
      Network server and the IBM DB2 Universal JDBC Driver"</a>
      mail list topic.
      </p>
      </answer>
    </faq>
    <faq id="derby_xa">
      <question>
      Can you execute a query that spans two Derby databases 
      across different JVMs?
      </question>
      <answer>
      <p>
      XA support using Network Server allows you to do this and the
      Derby Network Client, new in 10.1, supports this functionality.
      An example of establishing an XA connection is in the 
      <a href="http://db.apache.org/derby/docs/10.13/adminguide/cadminapps811478.html">Admin and Server Guide</a>.
      </p>
      </answer>
    </faq>
    <faq id="derby_faster">
      <question>
      Are there any tips to make Derby go faster?
      </question>
      <answer>
      <p>
      Here are two performance tips for coding applications:
      </p>
      <ol>
      <li> 
         Use PreparedStatement with dynamic markers('?') instead of Statement. 
         This will be faster since the statement does not need to be 
         recompiled every time. See the
<a href="http://db.apache.org/derby/docs/10.13/tuning/ctunperf18705.html">Use prepared statements with substitution parameters</a> and
<a href="http://db.apache.org/derby/docs/10.13/tuning/ctundepth29804.html#ctundepth29804">Avoid compiling SQL statements</a> sections of the Tuning Derby guide.
      </li>
      <li> 
        Avoid inserts in autocommit mode if possible. 
        Autocommitted inserts
        flush of the 
        log to the disk for each insert statement. 
        The commit does not return until a physical disk write has been 
        executed. 
        So to speed things up, run in autocommit false mode,
        execute a number of inserts in one transaction, and then explicitly 
        issue a commit.
      </li>
      </ol>
      </answer>
    </faq>
    <faq id="jdbc_lob">
      <question>
      Where is an example that shows how to insert a CLOB?
      </question>
      <answer>
      <p>
      The <em>Reference Guide</em> includes an 
      <a href="http://db.apache.org/derby/docs/10.13/ref/rrefclob.html">example
      that shows how to insert a CLOB</a>.
      Also
      <a href="http://mail-archives.apache.org/mod_mbox/db-derby-user/200509.mbox/%3c1126857139.2375.75.camel@pc977.sb.statsbiblioteket.dk%3e">this 
      derby-user post</a>
      provides another example.
      </p>
      </answer>
    </faq>
    <faq id="jdbc4">
      <question>
      Does Derby support JDBC 4.0?
      </question>
      <answer>
      <p>
      From release 10.2.2.0 onward, Derby distributions include compiled versions of JDBC4 drivers.
      </p>
      </answer>
    </faq>
  </faqsection>
</faqs>
