This article provides an introduction to the H2 Java SQL database.
H2 is an open source RDBMS written in Java.
It is an in-memory database.
It can be embedded in Java applications or run in the client-server mode.
You can download and add the h2 jar manually from h2database website or use Maven to download it for you.
To download it, refer the following link :
You can also use the following Maven dependency :
Starting H2 database
Once the H2 jar is available in your project, you can run the org.h2.tools.Console class as a Java application.
This will open the database console in browser.
Click “connect” and you will connect using H2 Generic server and default credentials(sa as id and blank password).
Creating a Table in H2
Here is the syntax for creating a sample Employee table :
CREATE TABLE Employee( ID INT PRIMARY KEY AUTO_INCREMENT, AGE INT, NAME VARCHAR(255));
DML Operations in H2
Here are some DML operations on the Employee table we created.
select * from employee;
insert into employee(age,name) values(20,'John doe');
update employee set age = 19 where id 1;
delete from employee where id = 1;
Refer this link for syntax details for DDL and DML statements :
© 2016, www.topjavatutorial.com. All rights reserved. On republishing this post, you must provide link to original post