Skip to content

InstallingTutorialDatabases

Guohui Xiao edited this page Dec 17, 2013 · 13 revisions

Table of Contents

Setting up the tutorial databases

There are two ways to setup the tutorial databases, the easy way using the pre-pared H2 database server downloadable from our website or setting them up manually using an existing DBMS (e.g., Postgres).

Using the pre-loaded H2 Server

This is the easiest and recommended way of using the tutorial databases. You will need to have Java JDK 1.6 installed. To use this option do as follows:

  1. Download the pre-bundled H2 server from our download website.
  2. Unzip the file into any folder, e.g., h2/
  3. Start the server using the scripts h2.sh or h2.bat. To do this in windows simply double click on h2.bat. In Mac/Linux do as follows:
    1. Open a terminal
    2. do cd H2_FOLDER where H2_FOLDER is the location where you unzipped the package.
    3. execute sh h2.sh
At this point a terminal window will be opened (nothing is printed there) but the database is now running. You will see a small yellow icon on your taskbar and now you will be able to do the tutorials.

Additionally you can browse the content of the databases. After the server starts, a browser window will open, there you may explore the content of the databases by connecting to each of them. Just replace the connection string with one of the following connection strings:

jdbc:h2:tcp://localhost/bookstores;DATABASE_TO_UPPER=FALSE

jdbc:h2:tcp://localhost/enrollment;DATABASE_TO_UPPER=FALSE

jdbc:h2:tcp://localhost/books;DATABASE_TO_UPPER=FALSE

jdbc:h2:tcp://localhost/helloworld;DATABASE_TO_UPPER=FALSE 

In all these cases the login is sa and the password field is empty.

Using Postgres

Alternatively you can install the databases in your existing local system by executing the SQL scripts we provide in this page. Each database uses a slightly different procedure to accomplish this. Here we explain how to do it in PostgreSQL, for MySQL users please see MySQL documentation, also there are many sites describing this operation.

We assume that you're familiar with PostgreSQL and have it installed to your computer. If not, see PostgreSQL website for detail information. We provide the SQL dump file so you can import the data instantly. Use this command line in your terminal:

$ psql [dbname] < [infile] [username]
where infile is the SQL dump file (*.sql) given by us. The database dbname is the target database (Note : you have to create an empty database first before executing this command). And lastly, the username is the database owner id. When you execute this command, the system will ask the user password. So, for example, you might execute the command below for installing the HelloWorld database.
$ psql helloworld < helloworld.sql postgres
Password for user postgres:

An alternative way is to use pgAdmin tool (see pgAdmin website). After you create an empty database, right-click on that database and select "Restore...". A dialog box will open and asks you the backup file. Select the dump file (*.sql) and click "OK". The restoration process will begin shortly and it is done automatically.

Resources

  1. tutorial.sqlfiles.zip. A zip with the SQL scripts that create all the databases
Clone this wiki locally