http://www.h2database.com/html/frame.html

 

最近一个桌面的程序需要使用嵌入式数据库,选择了很多不同的嵌入式数据,最终选择了H2,性能是一个很重要的原因,下图是h2提供的Performance的比较图

http://www.h2database.com/html/images/performance.png

 

h2是Thomas Mueller提供的一个开源的、纯java实现的关系数据库,在google上面有讨论组h2-database@googlegroups.com,Thomas Mueller也非常热情,回答问题非常及时。

 

下面说下我最终选择h2的原因:

(1)性能、小巧

(2)同时支持网络版和嵌入式版本,另外还提供了内存版

(3)有比较好的兼容性,支持相当标准的sql标准(实际上也不存在一个数据库能够100%符合标准)

(4)提供了非常友好的基于web的数据库管理界面

(5)支持hibernate



补充:
支持的事务隔离级别:

Transaction Isolation

This database supports the following transaction isolation levels:

  • Serializable
    This is the default level.
    To enable, execute the SQL statement 'SET LOCK_MODE 0'
    or append ;LOCK_MODE=1 to the database URL: jdbc:h2:~/test;LOCK_MODE=1
  • Read Committed
    Read locks are released immediately. Higher concurrency is possible when using this level.
    This is the isolation level used for many database systems.
    To enable, execute the SQL statement 'SET LOCK_MODE 0'
    or append ;LOCK_MODE=3 to the database URL: jdbc:h2:~/test;LOCK_MODE=3
  • Read Uncommitted
    This level means that transaction isolation is disabled.
    To enable, execute the SQL statement 'SET LOCK_MODE 0'
    or append ;LOCK_MODE=0 to the database URL: jdbc:h2:~/test;LOCK_MODE=0

When using the isolation level 'serializable', dirty reads, non-repeatable reads, and phantom reads are prohibited.

  • Dirty Reads
    Means a connection can read uncommitted changes made by another connection.
    Possible with: read uncommitted
  • Non-Repeatable Reads
    A connection reads a row, another connection changes a row and commits, and the first connection re-reads the same row and gets the new result.
    Possible with: read uncommitted, read committed
  • Phantom Reads
    A connection reads a set of rows using a condition, another connection inserts a row that falls in this condition and commits, then the first connection re-reads using the same condition and gets the new row.
    Possible with: read uncommitted, read committed

Table Level Locking

The database allows multiple concurrent connections to the same database. To make sure all connections only see consistent data, table level locking is used. This mechanism does not allow high concurrency, but is very fast. Shared locks and exclusive locks are supported. Before reading from a table, the database tries to add a shared lock to the table (this is only possible if there is no exclusive lock on the object by another connection). If the shared lock is added successfully, the table can be read. It is allowed that other connections also have a shared lock on the same object. If a connection wants to write to a table (update or delete a row), an exclusive lock is required. To get the exclusive lock, other connection must not have any locks on the object. After the connection commits, all locks are released. This database keeps all locks in memory.