Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are H2 and r2dbc-h2

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "what is H2 and r2dbc-h2". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is H2 and r2dbc-h2".

Brief introduction of H2 Database

What is H2 database?

H2 is a Java SQL database, an open source database that runs very fast.

The reason H2 is popular is that it can be run either as a stand-alone server or as a nested service and supports pure memory.

The jar package of H2 is very small, only 2m in size, so it is very suitable for nested databases.

If you are an embedded database, you need to add h3*.jar to classpath.

Here is a simple code to establish an H2 connection:

Import java.sql.*;public class Test {public static void main (String [] a) throws Exception {Connection conn = DriverManager. GetConnection ("jdbc:h3:~/test", "sa", ""); / / add application code here conn.close ();}

If the database for the given address does not exist

At the same time, H2 also provides a simple management interface, which can be started using the following command:

Java-jar h3*.jar

By default, you can access the management interface by accessing http://localhost:8082:

R2dbc-h3

R2dbc-h3 is an implementation of r2dbc spi. The same use of r2dbc-h3 also provides two modes of h3, one is the file system, and the other is memory.

At the same time, it also provides transaction support, prepared statements and batch statements support.

Maven dependency of r2dbc-h3

To use r2dbc-h3, we need to add the following dependencies:

Io.r2dbc r2dbc-h3 ${version}

If you experience the snapshot version, you can add the following dependencies:

Io.r2dbc r2dbc-h3 ${version} .BUILD-SNAPSHOT spring-libs-snapshot Spring Snapshot Repository https://repo.spring.io/libs-snapshot to establish a connection

H3 there are two connection methods, file and memory, let's take a look at how to establish the connection:

ConnectionFactory connectionFactory = ConnectionFactories.get ("r2dbc:h3:mem:///testdb"); Publisher

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report