H2 Database Introduction

Commonly used open source database: H2, Derby, HSQLDB, MySQL, PostgreSQL. Where H2, HSQLDB similar, very suitable for use as an embedded database, other databases most of them will need to install a separate client and server side.
H2 advantages:
1, h2 written in pure Java, and therefore not limited by the platform.
2, h2 only one jar file, is very suitable as an embedded database trial.
3 advantages, performance and functionality
 
A H2 database official website: http: //www.h2database.com/
H2 is an open source embedded database engine, using java language, limited by the platform, while providing a H2
A very convenient web console for operating and managing database content. H2 also offers compatibility mode compatible with some of the main
Database stream, having a more complete database features, such as support client / server connections, supports standard SQL language
Sentence, support for stored procedures and so on. Therefore, the use of H2 as a development, testing and demonstration of the database is very convenient, is not suitable
As a large-scale production database.
two.
a. Run (single process to access) in the memory
Only running in memory database, the database will be empty after the connection is closed, the test environment for
The connection string:
jdbc:h2:mem:DBName;DB_CLOSE_DELAY=-1
b. Embedded (single process accesses)
Persistence database stored as a single file
The connection string:
jdbc:h2:file:~/.h2/DBName;AUTO_SERVER=TRUE
~ / .H2 / DBName indicates a storage location of the database file, if the first connection it will automatically create the database
c. Service mode (multi-process access)
 web server: this operation mode supports the use of a browser to access H2 Console
 TCP server: Support Connection client / server
 PG server: PostgreSQL Client Support
H2 supports three service models:
Start tcp service connection string example:
jdbc: h2: tcp: // localhost / ~ / test using the user's home directory
jdbc: h2: tcp: // localhost // data / test use absolute paths
jdbc:h2:ssl://localhost:8085/~/sample
 DB_CLOSE_DELAY: Last connection requires a disconnection after being connected, do not close the database
MODE = MySQL: compatibility mode, H2 is compatible with multiple databases, this value can be:
DB2、Derby、HSQLDB、MSSQLServer、MySQL、Oracle、PostgreSQL
 AUTO_RECONNECT = TRUE: automatic reconnection after the connection is lost
AUTO_SERVER = TRUE: mixed mode starts automatically, allowing a plurality of open connections, the parameter is not supported
Memory operation mode
TRACE_LEVEL_SYSTEM_OUT, TRACE_LEVEL_FILE: trace output to the console or log file,
The value 0 is OFF, 1 to ERROR (the default), 2 INFO, 3 to DEBUG
 SET TRACE_MAX_FILE_SIZE mb: set the size of the trace log file, the default is 16M
d. Connect String Parameter
e. Start service mode, open the H2 Console web page
Start the service, execute the command line
java -cp h2*.jar org.h2.tools.Server
Run the following command to get a list of options and defaults
III. Run
H2 Database Introduction
At 22:39 on September 20, 2017
Page 1 of DB partition execute the following command to get a list of options and defaults
java -cp h2*.jar org.h2.tools.Server -?
 -web: H2 Console launch support services
 -webPort: service start port, default 8082
 -browser: start H2 Console web management page
 -tcp: Use TCP server mode is activated
 -pg: Use PG server mode is activated
Common options are as follows:
IV. Cluster (has not been the actual test)
H2 supports two servers running two databases to be clustered, two database backup for each other, if one server fails,
Another server can still work. The only other support services model cluster configuration.
a. Create a directory
Create two directory servers work
# mkdir server1
# mkdir server2
b. Start tcp service
Run the following command to start two were using tcp service model database in 9101,9102 port
java org.h2.tools.Server-tcp -tcpPort 9101-baseDir server1
java org.h2.tools.Server-tcp -tcpPort 9102 -baseDir server2
c. Create a cluster tool for use CreateCluster
java org.h2.tools.CreateCluster
-urlSource jdbc:h2:tcp://localhost:9101/~/test
-urlTarget jdbc:h2:tcp://localhost:9102/~/test
-user
-serverList localhost:9101,localhost:9102
If the two database does not exist, the command will automatically create the database. If a database fails, you can
Delete bad database file, restart the database, and then rerun the tool CreateCluster
d. Connect database
You can now be used as a clustered database connection string
jdbc:h2:tcp://localhost:9101,localhost:9102/~/test
e. monitor the operating status of the cluster
Can I use the following command to view the configuration of the cluster servers are running
SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME='CLUSTER'
f. limit
H2 clustering does not support load balancing for a transaction, so a lot of action results in two databases produce inconsistent
As a result, please be careful when performing the following operations:
RANDOM_UUID(), SECURE_RAND(), SESSION_ID(), MEMORY_FREE(), MEMORY_USED(),
CSVREAD(), CSVWRITE(), RAND()
Automatic growth column and identity column does not support clustering, when inserting data, you need to manually create the sequence value
Does not support the SET AUTOCOMMIT FALSE statement, if not need to be set up to automatically submit, the method can be performed
Connection.setAutoCommit(false)
H2 can be created by CreateCluster cluster tool, examples of the steps of (two in the analog data on a server
Library clustered):
• Dataflyer a tool to view and export the database
• DB Solo SQL Query Tool
V. able to access and view visualization tools H2 Database
Partition DB page 2 • DB Solo SQL Query Tool
• DbVisualizer Database Tools
• Execute Query Java to write the database tools
• Flyway Java to write the agile database migration tool
• fleXive JavaEE5 of open-source framework, can be used for the evolution of complex Web applications have been developed.
JDBC Console a small web application that provides a capability to execute SQL-based console community of H2
Surfaces, also supports JNDI data source.
• HenPlus a tool used to write Java SQL
• JDBC lint when we can use the JDBC API to help us write the correct efficient code
OpenOffice is a database application OpenOffice.org organization. It provides access to relational data sources
ability.
RazorSQL a SQL query tool can browse database, SQL statements editing, data pipe
Management.
• SQL Developer common database management front end.
• SQL Workbench / J free independent DBMS SQL tools
SQuirreL SQL Client graphical tools to view the structure of the database, browse the data, execute SQL
command
• SQuirreL DB Copy Plugin is used to copy data from one database to another database.
Page 3 DB's partition

Guess you like

Origin www.cnblogs.com/zhuyeshen/p/10956428.html