H2 is a disk-based or in-memory databases and tables, read-only database support, temporary tables. H2 provides transaction support (read committed), 2-phase-commit multiple connections, table level locking. H2 is a cost-based optimizer, using a genetic algorithm for complex queries, zeroadministration.

What is the use of H2 database in spring boot?

H2 is an embedded, open-source, and in-memory database. It is a relational database management system written in Java. It is a client/server application. It stores data in memory, not persist the data on disk.

What is difference between H2 and MySQL?

MySQL is a server – based database – it runs as a separate process from your application, and is commonly used in production deployments. H2 is a lightweight database, which can run entirely in-memory, or with disk storage, either in your application’s process (embedded) or in a separate process.

What kind of database is H2?

relational database management system

H2 is a relational database management system written in Java. It can be embedded in Java applications or run in client-server mode. The software is available as open source software Mozilla Public License 2.0 or the original Eclipse Public License.

Is H2 database SQL?

Welcome to H2, the Java SQL database. The main features of H2 are: Very fast, open source, JDBC API. Embedded and server modes; in-memory databases.

What is H2 database in Java?

H2 is an open-source lightweight Java database. It can be embedded in Java applications or run in the client-server mode. H2 database can be configured to run as in-memory database, which means that data will not persist on the disk.

Where does H2 database store data?

H2 can be configured to run as an in-memory database, but it can also be persistent, e.g., its data will be stored on disk.

Is H2 a good database?

As of 2019, H2 is a superb database. We use it in all of our standalone applications since 4 years and we see it minimizes a gap between SQLite and MySQL. It performs as fast as or faster than MySQL.

Is H2 database and hibernate same?

In this Hibernate H2 database tutorial, you will learn how to create a Hibernate Application to connect the H2 in-memory database. Hibernate is an object-relational mapping framework for the Java language. It provides a framework for mapping an object-oriented domain model to a relational database.

Does H2 use MySQL?

SQL Support

Compatibility modes for IBM DB2, Apache Derby, HSQLDB, MS SQL Server, MySQL, Oracle, and PostgreSQL.

Why H2 is not used in production?

The main reasons not to use H2 (or HSQLDB, or Derby) for production are: Probability of critical bugs: compared to the ‘big’ databases Oracle, IBM DB 2, MS SQL Server, MySQL, PostgreSQL, the Java databases are relatively new and therefore possibly not as stable (have bugs).

How do I create a database in H2?


  1. Add the h2*. jar to the classpath (H2 does not have any dependencies)
  2. Use the JDBC driver class: org. h2. Driver.
  3. The database URL jdbc:h2:~/test opens the database test in your user home directory.
  4. A new database is automatically created.

How do I setup my H2 database?

Install H2 Database

  1. Step 1: Download H2 Setup File. Download the latest version of H2 Database from the given link. …
  2. Step 2: Install H2 Database. After downloading we get the H2 Windows installer file (i.e. h2-setup-yyyy-mm-dd.exe) in the Downloads directory. …
  3. Step 3: Verify H2 Database Installation.

How do I connect my h2 database to my browser?

Access the H2 Console

You can access the console at the following URL: http://localhost:8080/h2-console/. You need to enter the JDBC URL, and credentials. To access the test database that the greeter quickstart uses, enter these details: JDBC URL: jdbc:h2:mem:greeter-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1.

How can I see my h2 database in my browser?

Accessing H2 Console. Start the spring boot application and access the console in the browser with this URL : http://localhost:8080/h2 . We can see the console like this. Now enter the configured username and password.

How do I read a h2 db file?

Connect to the embedded H2 database using the H2 console

Alternatively you can connect using the browser based H2 console. The easiest way to access the console is to double click the H2 database jar file at <installation-directory>\confluence\WEB-INF\lib\h2-x.x.x.jar .

How do I run a query in h2 database?

H2 Database – JDBC Connection

  1. Step 1 − Registering the JDBC database driver. Class. forName (“org. …
  2. Step 2 − Opening the connection. Connection conn = DriverManager. …
  3. Step 3 − Creating a statement. Statement st = conn. …
  4. Step 4 − Executing a statement and receiving Resultset. Stmt. …
  5. Step 5 − Closing a connection. conn.

What port does h2 run on?

However, the default port is 8080, and that port is already being used on my machine. EDIT As mentioned by Atul K below, the h2 web console is available on the configured server.

What is the default password for h2 database?

The default password is tisadmin. Select Connect. In the H2 Console, in the SQL statement pane, enter the following command: SET PASSWORD ‘<password>’. Note: The password must be in single quotes.

How does Intellij connect to h2 database?


  1. In the Database tool window (View | Tool Windows | Database), click the Data Source Properties icon .
  2. On the Data Sources tab in the Data Sources and Drivers dialog, click the Add icon ( …
  3. At the bottom of the data source settings area, click the Download missing driver files link.

How do I create a data source in Intellij?

To create our H2 data source, we’ll open the Database tool window (View -> Tool Windows -> Database) then click on the + button. There are various ways to create our connection. We’ll use the Data source from URL option. We’ll enter in our databse URL: jdbc:h2:file:./data/myDB and click OK.

How does IntelliJ connect to Database?

To add a new database connection (called a data source in IntelliJ), open the Database window View -> Tool Windows -> Databases, then click the + sign and select Data Source and then MySQL from the sub-menu. The defaults for the MySQL connection should for a local install of MySQL.

What is datasource in IntelliJ?

Data source is a location of data for your application. In IntelliJ IDEA, you can define the following data sources: Database data source: operational databases that contain data (see Database connection). Data Definition Language (DDL) files: SQL files that contain data definition language statements.