Java Embedded Database H2 Learning Summary (i) Getting started with the--H2 database

Source: Internet
Author: User

I. Introduction of H2 Database

Common open-source databases are: H2,derby,hsqldb,mysql,postgresql. Where H2 and hsqldb are similar, they are well suited for use as embedded databases, while the rest of the database needs to be installed on a separate client and server side.

Advantages of H2:
1, H2 is written in pure Java, so it is not limited by the platform.
2, H2 only a jar file, very suitable as an embedded database trial.
3. H2 provides a very convenient web console for manipulating and managing database content.

Second, H2 database download and installation 2.1, H2 database download

H2 Database: http://www.h2database.com/html/download.html

  

  

After the download is complete, get the compressed package as shown:

  

2.2. H2 Database Installation

The installation of the H2 database is very simple, unzip the downloaded compressed package directly, as shown in:

  

This way, the H2 database is installed even if the installation is complete

2.3. Test H2 Database

First introduce the directory structure of the H2 database

H2
|---Bin
| |---The jar package for the H2-1.1.116.jar//H2 database (driver is also inside)
| |---h2.bat//windows console startup script
| |---h2.sh//linux console startup script
| |---h2w.bat//windows console startup script (without a black screen window)
The help document for the---docs//H2 database (with a manual for the H2 database)
|---service//packaged into services through wrapper.
|---src//h2 the source code of the database
|---build.bat//windows build script
|---build.sh//linux build script

Run the H2.bat batch program to start the H2 database as shown in:

  

Open Browser, enter Address: http://localhost:8082 access the Web Console of the H2 database as shown in:

  

The ability to see this interface indicates that the H2 database can be used normally.

Third, simple use H2 database 3.1, Login H2 database Webconsole console

  

  

After the connection test passes, click the "Connect" button and log in to the test database Webconsole as shown in:

  

3.2. Create a table

Copy the sample SQL script provided by the H2 database as shown in the following example:

  

Execute the SQL script as shown in:

  

SQL Script Execution Results:

  

When all is done successfully, you can see the created test table as shown in:

  

3.3. Test database File storage location description

In the above operation, we use the URL of jdbc:h2:~/test to connect to the test database in JDBC mode, as shown in:

  

Then a test table is created in the test database and a crud operation is performed on the test table, which directory the file of the test database is stored in, and here it is necessary to explain what the symbol "~" means under the window operating system. Under the window operating system, the "~" symbol represents the user directory of the user currently logged into the operating system, so the test database file is stored in the user directory of the user who is logged into the operating system. For example, I am currently using the Administrator user to log into the operating system, so in the "C:\Documents and Settings\administrator\.h2" directory, you can find the database file corresponding to the test database, as shown in:

  

3.4. Create a new database

  

Click the "Connect" button, you can enter the GACL database console, as shown in:

  

At this point you can see the H2 automatically created GaCl database and GaCl users, and then in the E:\H2 directory can also find the GACL database corresponding database file, as shown in:

  

Similarly, we can create a table in the newly created GACL database and crud the table, as shown in:

  

The above is a simple introduction to the H2 database, and the next blog post will explain how to manipulate the H2 database in a Java program.

Java Embedded Database H2 Learning Summary (i) Getting started with the--H2 database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.