Friday 6 March 2015

H2 Database

H2 is very fast, open source in-memory database written in Java.

Installing H2 database
Download setup file from "http://www.h2database.com" and insall setup.

Start H2 console
click [Start], [All Programs], [H2], and [H2 Console (Command Line)].


A new console window appears like below.

Also, a new browser page should open with the URL http://localhost:8082.

You can click "Test Connection" button to check the connection.

Click on "connect" button.

CREATE TABLE employee
(
id int,
firstName varchar(30),
lastName varchar(30),
salary decimal,
mailId varchar(30),
PRIMARY KEY(id)
);

Paste above snippet and click "run" button. It creates table "employee".

Enter below statements in text area and press "run" button. It inserts 3 records into employee database.

INSERT INTO employee values(1, 'Krishna', 'Ananda', 100000.00, 'krishna@krishna.com');
INSERT INTO employee values(2, 'Arjun', 'Dhanunjay', 50000.00, 'arjun@arjun.com');
INSERT INTO employee values(3, 'Ptr', 'Ptr', 25000.00, 'ptr@ptr.com');

Enter following statement, to select data from table employee.
SELECT * FROM employee;




Prevoius                                                 Next                                                 Home

No comments:

Post a Comment