H2 database

database

Posted by Spencer on September 12, 2017

H2 database

H2 Database Java SQL 數據庫,功能強大,而且運行只需一個jar包即可. 官方描述:

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
Browser based Console application
Small footprint: around 1.5 MB jar file size
翻譯:
歡迎來到H2,Java SQL數據庫。H2的主要特點是:

非常快,開放源碼,JDBC API
嵌入式和服務器模式;內存數據庫
基於瀏覽器控制台應用程序
佔用空間非常小:大約1.5 MB的jar文件大小

Quickstart

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

Tutorial

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

Features

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

Cheat Sheet

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

与其他开源数据库比较

Connecting to a Database using JDBC

show codes: GitHub: https://github.com/SpencerZhang/h2-learn.git/

	CRAETE TABLE TEST(ID INT PRIMARY KEY,NAME VARCHAR(255));
	INSERT INTO TEST VALUES(1,'Hello');
	INSERT INTO TEST VALUES(2,'World');
package com.spencer.h2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class H2Demo01 {
	public static void main(String[] a) throws Exception {
		Class.forName("org.h2.Driver");
		Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
		ResultSet rs = conn.createStatement().executeQuery("select * from test");
		// ResultSet rs = conn.createStatement().executeQuery("select * from
		// TEST");
		while (rs.next()) {
			System.out.println(rs.getInt(1));
			System.out.println(rs.getString(2));
			// System.out.println(rs.getInt("ID"));
			// System.out.println(rs.getString("NAME"));
			// System.out.println(rs.getInt("id"));
			// System.out.println(rs.getString("name"));
		}
		rs.close();
		conn.close();
	}
}

–EOF–


本文链接:H2 database
作者: Spencer
出处: https://spencerzhang.github.io
本文基于 知识共享署名-相同方式共享 4.0 国际许可协议发布,欢迎转载,演绎或用于商业目的,但是必须保留本文的署名 Spencer及链接。