1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

Note: A PDF copy of this page is available for offline reading.

Getting Started using the SQuirreL SQL Client

The SQuirreL SQL Client is a graphical program written in the Java programming language that will allow you to view the structure of a JDBC-compliant database, browse the data in tables, issue SQL commands and much more. This document will demonstrate how install the client and configure it to connect to and work with an Apache Derby database. Derby is a full-featured, open source relational database management system (RDBMS) that is based on Java technology and SQL (The Apache Software Foundation 2010). The Derby database was selected because it can be setup very easily. The steps for configuring the SQuirreL SQL Client to work with any other database management system will be very similar.

Prerequisites

The SQuirreL SQL Client is a Java application, and as such, it requires a Java 6 runtime environment (JRE) which can be downloaded from Oracle. Follow the instructions downloading and installing Java 6 using the executable installer. Earlier versions of the JRE (for example Java 5) are not compatible with the latest versions of the SQuirreL SQL Client. Apple’s current version of Mac OS X (10.6/Snow Leopard) comes with Java 6 pre-installed. However, Apple and Oracle have made arrangements for Oracle to ship updates to the JRE for Mac OS X in future versions of that operating system, so for newer releases of Mac OS X, check Oracle’s website for updates.

Once the Java 6 runtime environment is installed, the install jar for the SQuirreL SQL Client can be found here: http://www.squirrelsql.org/#installation. As of this writing, the current version is 3.2.0, but this page will always contain a reference to the latest version that is available. In the section titled “The most important downloads”, click on either link for the install jars depending on your computer operating system (that is, either the one for Windows/Linux/others or the one for Mac OS X). When your browser prompts, choose to download and open the file with Java. If that fails for any reason, save the file to your desktop, and double-click on it to launch the default application, which should be Java “jar” files. Assuming that is successful, the installer will display a welcome dialog as shown in Figure 1.

Installation Welcome Dialog
Figure 1. Installation Welcome Dialog

Click the “Next” button to continue the installation. Some information about what’s required to run the application and what the software installer provides follows. Click the “Next” button again, and the dialog prompts for a path to the location where the application should be installed. On some versions of Windows, the “C:\Program Files” is secured for Administrator use only. However, the update feature of the SQuirreL SQL Client requires write access to these files. For this reason, it is recommended that a directory be chosen for installing personal applications such as this one. For example, if your Windows system allows you to create a directory on the “C:\” drive, you might create a directory called “C:\tools\”. In any case, set the installation path to a folder in which the application should be installed as shown in Figure 2.

installation path
Figure 2. Setting the installation path

Click the “Next” button to continue the installation. The dialog now presents a list of “packs” that can be installed, which include required software as well as optional plug-ins. A plug-in is usually a piece of software that can be added (or plugged in) to the application to extend its capabilities. The SQuirreL SQL Client installer ships database-specific plug-ins for each of the major database vendors which allow the application to work optimally with the corresponding database. The “Base” pack is the only one required for installation. However, the “Standard” pack is a group of plug-ins that is optional, but highly recommended and pre-selected. The only other optional plugin that should be installed for the purpose of this demonstration is the “Derby” plug-in as shown in Figure 3. If you plan to work with other databases, you can select additional plug-ins now, or use the software update feature to fetch them from the Internet at a later time. Click the “Next” button to continue, and a progress bar showing installation of the selected software packs is displayed. Click “Next” again and on some systems shortcuts for the start menu or desktop can be optionally created. Click “Done” to finish the installation.

Selecting packs to install
Figure 3. Selecting packs to install

Now that the SQuirreL SQL Client application is installed, we will launch it and configure it to connect to a new Derby database. The Mac OS X install jar (squirrel-sql-<version>-MacOSX-install.jar), will create a launch icon in your applications folder that you should double-click . On all other systems, either use the shortcut that was created by the installer, or open the location where the application was installed, and double-click on the launch script (squirrel-sql.bat for Windows or squirrel-sql.sh for UNIX-based systems). A splash screen should be displayed as shown in Figure 4.

Splash Screen
Figure 4. Splash Screen

The main window of the application along with a help window is displayed as shown in Figure 5 when the splash screen image closes. You may close the help window and access it at any time by using the “Help” menu in the main window.

Main application window
Figure 4. Main Window

The next step to connect to a database is to configure a JDBC driver. A JDBC driver allows an application written in the Java language to connect to a specific database. The driver is a piece of software that is usually written for only one database product (that is, Oracle, MySQL, SQL-Server, DB2, Derby, etc.). For each database product, there can be as many as 4 different “types”, known as Type-1 through Type-4. When choosing a JDBC driver, always look for Type-4 drivers as these are usually the fastest, most portable and easy to setup type of driver. The JDBC driver, and the fact that the SQuirreL SQL Client is written in Java, is what makes the application so appealing. That is, it is possible to use only one tool to interact with many different database products simply by using different JDBC drivers.

Before we can configure the Derby JDBC driver, we need to download the Derby database from the Apache Software Foundation. Derby is an open-source application that is distributed in a small archive file which can be extracted to a location on your machine (This is another case where a personal applications folder – C:\tools – may come in handy on Windows machines). The Apache Derby website (http://db.apache.org/derby/) has a link to download the archive. You should opt for the “Latest Official Release”, which as of this writing is 10.7.1.1 and is only about 46 MBs in size. The archive contains all of the files needed to run the Derby database and comes in a archive format which is suitable based on the operating system (*-bin.zip for Windows, *-bin.tar.gz for all others). Since there are a few different types of archives, be sure to select ones that end in “-bin”, before the archive format extension. Extract the archive to a location on your machine (for example, “C:\tools”). This will create a top-level directory named according to the version. Inside of this folder, there is a “lib” folder that contains the Derby software jars including a JDBC Driver that can be loaded into the SQuirreL SQL Client.

Now we can configure the Derby JDBC driver in the SQuirreL SQL Client. In the main window, there are two buttons on the far left-side of the application entitled “Aliases” and “Drivers”. Click on the “Drivers” button and the drivers panel will appear. This panel contains templates for each of the database product that is known to have a JDBC driver that can be loaded into the SQuirreL SQL Client. Near the top of the list is the “Apache Derby Embedded” driver template. Double-click on this entry and a “Change Driver: Apache Derby Embedded” dialog will appear as shown in Figure 6

Change driver dialog
Figure 6. Change driver dialog

Select the “Extra Class Path” tab in the middle of the dialog. Click the “Add” button on the right and navigate to the “lib” directory under the directory where the Apache Derby software was extracted. Select the jar named “derby.jar” and click “Open”. This will add the location of the Derby JDBC embedded driver jar file to the “Extra Class Path” list. Click the “OK” button and a green status message should appear in the message panel on the bottom of the main window indicating that driver was successfully registered. An example of this is shown in Figure 7.

Driver successfully registered message
Figure 7. Driver successfully registered

Additionally, the red ‘X’ icon next to the “Apache Derby Embedded” driver will now appear as a blue check mark to indicate that the driver was successfully registered and is ready for use.

The next step is to create an Alias for the Derby database connection. Aliases store information that is used to make the connection to a database. Click on the “Alias” button and the drivers panel will be replaced with an “Aliases” panel. To add an alias click the blue “+” (plus sign) at the top of the Aliases panel and an “Add Alias” dialog will appear. The name field is required and gives the Alias a label that helps distinguish it from other aliases. You may type “derby” or any other text in the name field. Click on the driver drop-down list and select “Apache Derby Embedded”. The URL field is now populated with a template URL. Since it is possible to have multiple instances of a database product running on your network or even your computer, a JDBC URL is required to tell the JDBC driver which database to make a connection to. Since we are using the Derby embedded database driver, we can take advantage of the easy setup that Derby provides, by telling the Derby driver to create a database in a directory of our choosing when we attempt our first connection. This can be done with a JDBC URL that looks like this:

jdbc:derby:c:\tools\derbydb;create=true

You should replace “C:\tools” with a directory that can be written to. The first time a connection is made using this URL, Derby will create a directory called “derbydb” and store files in it that hold the information that is stored in the database. For the “User Name” field, enter the text “APP” (without the quotes). The “Password” field can be left empty for this exercise. Select the “Auto logon” checkbox. The “Add Alias” dialog will now look similar to Figure 8.

Adding a derby database alias
Figure 8. Adding a Derby database alias

Click the “Ok” button to save the Alias. Now the “Aliases” panel will have one entry in it labeled “derby”. Double click on this alias to create and connect to the database. The database will only be created the first time the connection is made. Subsequent connections may provide a warning message, but will ignore the “create=true” property in the JDBC URL. After the first connection, the text starting with a semi-colon on the end of the JDBC URL (“;create=true”) can be removed by modifying the alias. To modify an alias in the aliases panel, select the alias entry and click the pencil icon or right-click and choose “Modify Alias”.

Now that we have connected to the database, click on the SQL tab to access the SQL script editor. The following SQL statements should be typed into the script editor, ensuring that there is one line of white space between each statement and the next.

	create table test ( myid integer );

	insert into test values (0);

	insert into test values (1);

	select * from test;

To run an SQL statement, place the cursor anywhere on the same line that the statement to be executed is and click the “Running Man” icon above the “SQL” tab, or press Ctrl-Enter key combination. The line that the cursor is on will be highlighted yellow. Run each of the above SQL statements in order to 1) create a test table, 2) add two rows of data, and 3) select that data from the test table. After executing all of the statements, you should see a result tab appear between the editor and the message panel displaying a table of results as shown in Figure 9.

SQL script editor
Figure 9. SQL script editor

To see a list of tables that have been created in this database (along with their contents) you can use the “Objects” tab, and double-click the “APP” node under “derby”, followed by double-clicking the “TABLE” node. Click on the “TEST” table, and then the “Content” tab on the right side of the application to show the records in the TEST table as shown in Figure 10.

TEST table contents
Figure 10. TEST table contents

This has been a short introduction to installing the SQuirreL SQL Client and connecting to a new Apache Derby database. This guide has demonstrated how to obtain and install the prerequisite Java Runtime Environment (JRE), Apache Derby database software and the SQuirreL SQL Client. Additionally, the SQuirreL SQL Client application was configured to use the Derby JDBC embedded driver to create a new database, connect to it and issue SQL statements to verify that the database was created successfully. For more information about using the SQuirreL SQL Client, see the “Help” section, or post questions to the user mailing list which can be subscribed to at https://lists.sourceforge.net/lists/listinfo/squirrel-sql-users.

References

Apache Software Foundation. "Introduction to Derby." Getting Started with Derby. Apache Software Foundation, 1/1/2010. Web. 21 Dec 2010. <http://db.apache.org/derby/docs/dev/getstart/>.

Attachments