You are on page 1of 10

CSCI 466

Assignment Description

Homework Assignment # 07

Fall, 2013

In this assignment, each student will use the ij tool of the Apache Derby relational database management system (RDBMS) to: 1. 2. 3. 4. 5. 6. create & connect to a new database, create a schema, create a table belonging to the newly created schema, insert tuples into the newly created table, use a SELECT statement to view the tuples after inserting them, and create & execute a single SQL script that accomplishes all of the preceding steps.

Each student will achieve all of the above goals by completing the steps outlined in detail on the following pages. Turn In Each student, in order to demonstrate to the instructor that he or she has completed this assignment, must submit (via Blackboard) a PDF file containing a series of screenshots of Windows PowerShell showing her or his successful completion of each of the steps. [The PDF document could be drafted in Microsoft Word, which could then be saved as PDF for submission.] Each PowerShell screenshot must include that students username. (See http://stackoverflow.com/questions/2085744/how-to-get-current-username-inwindows-powershell for instructions regarding how to display your username in PowerShell.)

Late Penalty There is a 20 % late penalty for each day that this assignment is late.

The following pages outline in detail how to achieve the outcomes required by this assignment.

Setting Up Derby Database and Using Derbys ij Command-Line Interface


Installing Derby Note: you may skip this step if you have already installed Derby on your MACS Computer Lab computer. On the other hand, feel free to complete this step if youd like the practice. Using a web browser, visit http://db.apache.org/derby/derby_downloads.html. Download the latest official release (10.10.1.1 as of 31 OCT 2013). Download db-derby-10.10.1.1-bin.zip.

Save to your folder as H:\db-derby-10.10.1.1-bin.zip. For Dr. Solheim, the ZIP file is saved in folder jasolheim on StudentLogon Server (labsvm) (H:).

Youll see it saved as db-derby-10.10.1-bin.zip, as shown below.

After download is complete, unzip db-derby-10.10.1-bin.zip by right-clicking on its icon and selecting Extract All. You may extract files to the directory H:\.

You should then see the following on your computer:

Viewing Derby Manuals & Getting Started with Derby Using your web browser, go to http://db.apache.org/derby/manuals. Click on the most recent non-alpha manuals (10.10 Manuals as of 31 OCT 2013). Click on Getting Started with Derby (either PDF or HTML).

Click on Setting the Environment Variables.

Set the DERBY_HOME environment variable to the location where you extracted the Derby bin distribution. For Dr. Solheim that location is H:\db-derby-10.10.1.1-bin. The method of setting this environment variable could vary. As of 31 OCT 2013, on the Rarick Hall 206 computers the method is as follows: 1. Start Windows PowerShell. 2. Create environment variable DERBY_HOME as shown here:

Make sure that your PATH environment variable includes a path to a java.exe executable file. On Dr. Solheims RH 206 computer, a path to a java.exe file is C:\Progra~1\Java\JRE7\bin\java.exe. Using Windows PowerShell, you can add this to your PATH environment variable as follows:

Add the DERBY_HOME/bin directory to the PATH environment variable. Using PowerShell, this can be done as follows:

Running SysInfo Now, return the the Derby Manuals, and Running sysinfo. Although its not required, we could run the Derby "sysinfo" tool to display information about our Java environment and our version of Derby. In PowerShell, you can do this as follows:

Using Derbys ij Tool You can use Derbys ij tool to submit SQL scripts or interactive SQL queries to a Derby database. To start ij from Windows PowerShell, do this:

Notice ijs command line prompt, ij>. At this prompt, you can interactively submit SQL commands to Derby.

Later, when you are ready to quit the ij tool, use the exit command:

Using ij to Connect to, and Disconnect from, a Database A Derby user must first connect to a particular database before submitting SQL commands to that database. Information about connecting to a Derby database can be found at http://db.apache.org/derby/docs/10.10/tools/ttoolsij97656.html. Here is how one could connect to a Derby database named BookstoreDatabase.

The above command connects to the specified Derby database, and creates that database if it does not already exist. The H:/ could be a different path if you wish to locate the database in a different folder. Later, when you have finished working with this particular database, you should disconnect from it using the disconnect command, which is described at http://db.apache.org/derby/docs/10.10/tools/rtoolsijcomref20382.html. See the following screenshot:

Using ij to Create and Drop a Schema A Derby user would use a schema to organize her or his database tables and other database objects. One can have different schemas for different databases, such as one schema for the Melody database, and another schema for the Math Relays Registration database. The SQL command to create a schema is at http://db.apache.org/derby/docs/10.10/ref/rrefsqlj31580.html. Here is how one would create a schema named Bookstore:

If you later want to drop (delete) the Bookstore schema, you would use a form of the drop command, like this:

The DROP SCHEMA command is described at http://db.apache.org/derby/docs/10.10/ref/rrefsqlj31648.html. The schema you want to drop must be empty (contain no table or other database objects) before the drop will succeed.

Creating and Dropping a Database Table The CREATE TABLE command creates a table belonging to a schema. Suppose you want to add an Author table to your Bookstore schema.

Here is an SQL command that creates the AUTHOR table in the BOOKSTORE schema:

Dont do this now, but if you later decide that you want to drop (delete) the AUTHOR table, heres how: DROP TABLE BOOKSTORE.AUTHOR ; Inserting Tuples (aka Rows) into a Table Here is how you would insert tuples (aka rows) into your table:

You can find out more about SQLs INSERT command at http://db.apache.org/derby/docs/10.10/ref.

Viewing a Tables Tuples To see what tuples a table currently contains, use the SQL SELECT command, like this:

Or, if youd like to see only the authors last names & dates of birth, do this:

There is more about SQLs SELECT statement at http://db.apache.org/derby/docs/10.10/ref. Deleting Tuples from a Table You can remove tuples from a table like this:

Using Derbys ij Tool to Run an SQL Script You could place all of your SQL statements into a single file, and then have Derbys ij tool execute all of the statements in that file. For example, you could use a simple editor (like Notepad) to create a file named, say, Bookstore_Script.SQL containing the following SQL statements:

Finally, to have the ij tool execute all of the SQL statements contained within your script, do this:

The above screenshot assumes that the script Bookstore_Script.SQL is located in the H:\ directory.

You might also like