Introduction

This article explains how to set up and use SQuirreL, an SQL viewer and editor.
SQuirreL is a solution for any platform since it's written in Java. It is also
an excellent browser since it supports nearly every RDBMS in existence, in
particular, MySQL, which I use here as my illustration. The advantage of using
SQuirreL over the native software that ships with each database is that the
interface—and therefore your work habits—can remain the same. This
isn't important if you ONLY work with one database. I have worked with 4 or 5
over the last few years and 3 simultaneously when I wrote this how-to.

Note that the more I use SQuirreL, the more I like it. I even use it just a
little for MongoDB, though it's too silly to do much with there.

How to set up SQuirreL on Linux

Download SQuirreL installation JAR by clicking on the icon at the top of
this page.

Run the installation JAR:

russ@taliesin: ~/Downloads> java -jar squirrel-sql-3.1-install.jar

Follow the installation steps as you normally would. Note that there are
many options you'll want to include that depend on how you'll be using it.

If you prefer, create a launcher for your desktop or menu pane. The JAR
to run is on the path, <installation-path>/squirrel-sql.jar.
(There is an "acorn" icon under subfolder icons to use if you
like.) Otherwise, you'll launch SQuirreL using the command:

If on Windows 7, launch as just noted, but do not attempt to
install on C:\Program Files\squirrel-sql-3.1\ as proposed,
but on a path that belongs to you (such as
C:\Users\russ\dev\SQuirreL\).

Follow the installation steps as you normally would. Note that there are
many options you'll want to include that depend on how you'll be using it
such as MySQL, Oracle, PostgreSQL, etc.

Create a shortcut for your desktop and/or start menu. Then edit the
shortcut's properties to set the Target: field to
C:\Windows\System32\java.exe -jar
C:\Users\russ\dev\SQuirreL\squirrel-sql.jar if not already set to
that.

Change the Start in: path if you like. I set mine to the root of
my development area (C:\Users\russ\dev).

There is an "acorn" icon under subfolder icons to use if you like.

My experience is that this is necessary on Windows 7. I haven't set up
SQuirrel on previous versions of Windows since I principally use Linux
anyway.

How to launch SQuirreL and set up MySQL

This set up is for MySQL as an illustration.

Launch SQuirreL as implied in the above instructions.

Go to Windows -> View Aliases.

Click the blue plus sign to add an alias.

Name the alias (MySql-dvdcatalog).

Change the driver to MySQL Driver.

Change the URL to the one being used in your Java program, e.g.:
jdbc:mysql://localhost/DvdCatalog

Change the username and password.

If you choose, click the Auto logon and/or Connect at
Startup boxes. That way, it will come right up at launch on the
database you're working on.

Click Test to see if it works.

If your driver is missing, (which it will be)...

Go to Windows -> View Drivers.

Double-click the (MySQL) driver.

Fill out the dialog:

(Leave the name alone unless you really want to change it.

Click Extra Class Path tab.

Click Add.

Navigate in the filesystem to your downloaded connector, e.g.:
C:\Users\russ\dev\downloads\mysql-connector-java-5.1.12\mysql-connector-java-5.1.12-bin.jar

Click Open.

Fill in the Class Name: field. This isn't obvious. In the
case of MySQL, it's com.mysql.jdbc.Driver.

How did I know this? Because when I wrote my first sample SQL
application years ago and learned how to use MySQL's JDBC connector
in Java code, this was the class I used. (If I stumble upon more
cogent advice for this step, I promise to come back and add it.)

Click OK.

Return to Windows -> View Aliases and double-click the
alias you've already set up (to use MySQL). You should now see the
database particulars (assuming you have a database already set up and
working), for example,

SQuirreL and those pesky commas

SQuirreL displays IDs (long integer numbers) using commas which makes them a
lot easier to read in terms of understanding how long they are (in groups of
3). However, in practical development situations where you're copying and
pasting what's in those columns, it quickly gets old having to remove the
commas (which Java, C/C++, etc. find asyntactic). To rid SQuirreL of this, ...

Open File -> Global Preferences.

Click Data Type Control.

Scroll down near bottom to FLOAT, REAL, DOUBLE, NUMERIC.

Click User default format.

If you want this setting to be permanent, choose File -> Save
Preferences.

Where to go from here?

The base assumption is that you already know how to peruse a database to look
at its tables, rows and cells. If this is not the case, you might instead use
MySQL's browser and follow the information at
MySQL: The Database Browser. Or learn using other databases and database
tutorials.

In this case, I just wanted a glimpse inside my database to see its tables as I
built them from my application code. Comparing the previous illustration and
this one here, you'll see how this is done.

Appendix: Setting up Oracle JDBC

I've had occasion to set up SQuirreL for use with a local, Oracle database. I
use the JDBC thin client. I created the alias thus:

(Yours will have an actual name in a couple of places; I've erased my alias
name since I aligned it with my commercial database and its identity is no
one's business, but my own.)

Of course, when I went to set up the driver, it wasn't there. The driver's name
was correctly guessed by SQuirreL, but I needed to go to the Oracle site to
download the driver.

Then, I accepted the license agreement and scrolled down to
Oracle Database 10g Release 2 (10.2.0.1.0) JDBC Drivers—what
I needed.

I chose ojdbc14.jar to download because I wanted Java 1.4/1.5 or
later support (and didn't care, for now, about whether it was debuggable
or not because I'm only using it for SQuirreL and not in my product).

I downloaded this driver (JAR) to
/home/russ/dev/downloads/oracle-jdbc-driver. Then, I clicked on the
Extra Class Path tab, clicked the Add button, and navigated
to my new driver, to add it. When I clicked OK, SQuirreL was very
happy and life went on just as if I were using the kinder, gentler database
(MySQL).

Oracle error codes

If you see error codes, you can visit
Oracle Error Codes for a
handy look-up and explanation of them.

Appendix: Setting up PostgreSQL JDBC

By now, you can figure this out; I followed the
MySQL instructions above and it worked right off.
Here's what I used to look at a local database named "acme".

Appendix: Setting up MongoDB JDBC

Seems bizarre, but it's useful for a quick look, easier sometimes than the
MongoDB command-line shell. Incidentally, you don't need a username and
password for the connection (if that doesn't make sense—and it usually
doesn't).