# Quick Start with Embedded eXtremeSQL in Java

> The principle classes for most eXtremeSQL Java applications are Database, SqlLocalConnection and SqlResultSet. The SqlLocalConnection is normally instantiated by calling the Database `connectSql()` method. Then SqlLocalConnection method `executeStatement()` is called to execute SQL `insert`, `update` and `delete` statements. Alternatively SqlLocalConnection method `insert()` can be called to insert objects of database classes and `currentCursor.update()`and `currentCursor.remove()` can be called to update or delete objects. Method `executeQuery()` is called to execute a `select` statement returning a SqlResultSet. Then various SqlResultSet methods can be used to process result sets. The following sections will walk through the steps for building a simple Java eXtremeSQL application. In addition, note that there are Java SDK samples that demonstrate specific eXtremeSQL features.

> ## Database definition

> For Java applications the database is defined using native Java class syntax applying special annotations (See here for a detailed explanation). For this example application we will use a schema defined as follows:

>         @Persistent(AutoID = true)
>         class Person
>         {
>             @Indexable(Type = Database.IndexType.BTree, Unique = true)
>             public String name;

>             public unsigned int ordinal;
>         }

> ## Open the database

> To open the database we first instantiate a Database object `db` in order to call its `Open()` method. There are a number of constructors for the Database class. For this sample we use the default constructor. The Database class `Open()` method has three overloads; we will call the version which allows us to specify the following properties for an in-memory database:

> - name - a string identifying the database
> - parameters - a DatabaseParameters object (see explanation below)
> - size - the total amount of memory available for the database

> The DatabaseParameters class has a number of properties. The property `Classes` must be initialized with an array of classes to be stored in the database. For this example there is simply the class Person. In the following code snippet we instantiate the Database object, define the DatabaseParameters `classes` and the memory page size (the basic unit of memory access) properties, then call the `open()` method.

> To complete this step we will call the `db.close()` method to terminate the database instance. The sample code for `Program.cs` so far looks like this:

>         public static void main(String[] args)
>         {
>             static final int PAGE_SIZE = 128;
>             static final int DATABASE_SIZE = 16*1024*1024;

>             Database db = new Database();
>             Database.Parameters parameters = new Database.Parameters();

>             parameters.memPageSize = PAGE_SIZE;
>             parameters.classes = new Class[]{Person.class};

>             db.open("PersonDb", parameters, DATABASE_SIZE);

>             // Do database processing

>             db.close();
>         }

> ## Populate and query the database using SQL

> To populate the database using SQL instantiate a SqlLocalConnection object and call its `executeStatement()` method as follows:

>             SqlLocalConnection con = db.connectSql();
>             con.executeStatement("insert into Person values('Luke Skywalker', 0)");
>             con.executeStatement("insert into Person values('Han Solo', 1)");

> Then to query the database we call the SqlLocalConnection `executeQuery()` method to instantiate a SqlResultSet object `result`:

>             SqlResultSet result = con.executeQuery("select * from Person") );

> ## Processing query results

> The SqlResultSet object returned from `executeQuery()` is a dataset that has numerous methods for extracting the result rows and information about the columns, etc. But presenting these details is beyond the scope of this quick start demonstration. Please see QueryResult processing for details and the Java SDK samples for several examples.