當前位置:首頁 » 數據倉庫 » h2資料庫使用基於內存
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

h2資料庫使用基於內存

發布時間: 2022-09-15 11:20:58

A. h2創建資料庫語句

h2創建資料庫語句如下:
CREATE TABLE TEST AS SELECT * FROM CSVREAD('test.csv');//csv文件數據創建test表 CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255)) AS SELECT * FROM CSVREAD('test.csv');/創建test表,csv文件相應的列插入到test表相應的欄位

H2資料庫介紹
常用的開源資料庫:H2,Derby,HsqlDB,MySQL,PostgreSQL。其中H2,HSQLDB類似,十分適合作為嵌入式資料庫使用,其它的資料庫大部分都需要安裝獨立的客戶端和伺服器端。
H2的優勢:
1、h2採用純Java編寫,因此不受平台的限制。
2、h2隻有一個jar文件,十分適合作為嵌入式資料庫試用。
3、性能和功能的優勢
H2比HSQLDB的最大的優勢就是h2提供了一個十分方便的web控制台用於操作和管理資料庫內容,這點比起HSQLDB的swing和awt控制台實在好用多了。

B. 如何使用H2資料庫來創建存儲過程

Visual Studio簡稱VS,是微軟開發的專門用於編寫程序的大型編程工具或編程平台,是基於.Net平台的。.NET 即Microsoft XML Web services 平台。XML Web services 允許應用程序通過 Internet 進行通訊和共享數據,而不管所採用的是哪種操作系統、設備或編程語言。.Net能提供一種它們共同無縫通訊的橋梁。
C#和C一樣,是一種編程語言,語法類似於C或C++,但較C和C++使用更簡便,主要特點是封裝了大量的類,並保存在相關的類庫中,使用時只需要引用相關的命名空間即可。asp.net是專門用於開發網站系統的一種開發技術,適應於開發B/S架構的系統。資料庫SQL一般指MS SQL,是用來存儲應用程序所需要的基礎數據和用戶輸入相關需要保存的數據的。

C. 怎麼遠程訪問H2資料庫的內存模式

簡單來說就是用jdbc:h2:mem:h2db來建立內存模式,並建表,
然後jdbc:h2:tcp://192.168.20.141:8082/mem:h2db來訪問上面的內存資料庫

package test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.tools.Server;

public class H2Demo {
private Server server;

private String port = "8082";
private static String sourceURL1 = "jdbc:h2:mem:h2db";
private static String sourceURL2 = "jdbc:h2:tcp://192.168.20.141:8082/mem:h2db";

private String user = "shorturl";
private String password = "123456";

public void startServer() {
try {
System.out.println("正在啟動h2...");
server = Server.createTcpServer(
new String[] { "-tcpPort", port }).start();
} catch (SQLException e) {
System.out.println("啟動h2出錯:" + e.toString());
// TODO Auto-generated catch block
e.printStackTrace();
throw new RuntimeException(e);
}
}

public void stopServer() {
if (server != null) {
System.out.println("正在關閉h2...");
server.stop();
System.out.println("關閉成功.");
}
}

public void useH2() {
try {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection(sourceURL1,user, password);
Statement stat = conn.createStatement();
// insert data
stat.execute("CREATE MEMORY Table TEST(NAME VARCHAR)");
stat.execute("INSERT INTO TEST VALUES('Hello World')");
//stat.execute("delete mappedURL");

// use data
ResultSet result = stat.executeQuery("select name from test ");
int i = 1;
while (result.next()) {
System.out.println(i++ + ":" + result.getString("name"));
}
result.close();
stat.close();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void useH2i() {
try {
Class.forName("org.h2.Driver");
//Connection conn = DriverManager.getConnection("jdbc:h2:" + dbDir+";AUTO_SERVER=TRUE;MVCC=TRUE",user, password);
Connection conn = DriverManager.getConnection(sourceURL2,user, password);
Statement stat = conn.createStatement();
// use data
ResultSet result = stat.executeQuery("select name from test");

D. H2資料庫

According to documentation, closing the last connection closes the database and when closing the database, the database is automatically compacted for up to 200 milliseconds
.
I guess these together may cause data loss & corruption when a
single connection is repeatedly created, data altered, connection
closed, new connection created, etc. - eventually resulting in
exception such as "Block not found in id [1, -128, 8, 42] [1.4.186/50]"
when trying to access the DB. Version 1.3.176 (last stable) works fine with this, version 1.4.186 crashes and corrupts data.

The
behavior can be fixed by appending ";DB_CLOSE_DELAY=-1" to the DB URL,
i.e. disabling autoclosing DB when last connection is closed. I though
it might have had something to do with 1.4's new "FS" file locking
protocol, but changing that to old "FILE" doesn't seem to help.

Of
course this is not how a DB connection is typically used - when using a
connection pool, this would go unnoticed - and I found this purely by
accident. But it's a bug anyway, isn't it?

Best Regards,
Joonas

狗哥找的

E. h2資料庫在linux伺服器怎麼使用

簡單來說就是用jdbc:h2:mem:h2db來建立內存模式,並建表, 然後jdbc:h2:tcp://192.168.20.141:8082/mem:h2db來訪問上面的內存資料庫 package test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; imp...

F. asp.net 使用 h2 內存資料庫

提供一個下載的地方
http://download.csdn.net/detail/yixiaoping/5956595
H2就不做很多介紹了。資源包內容列表是我進行H2預研是收集的H2資料,應該是最全面的的了:

1、h2.pdf (H2 API)

2、h2-1.3.173.jar (截止2013-8-15最新的H2.jar)

3、h2-2013-07-28.zip (截止2013-8-15最新的H2服務,包括API\JAR\服務)

4、H2Database_SQL語法.doc

5、H2Database高級特性.doc

6、H2Database聚合函數.doc

7、H2Database連接配置.doc

8、H2Database數據類型.doc

9、H2Database中文教程.doc

10、H2內存資料庫h2部署操作手冊.docx

11、H2內存資料庫安裝與維護.doc

12、H2資料庫基礎知識.docx

13、H2資料庫使用.doc

G. h2內存資料庫建表的時候,如何實現自增列建表sql

自動遞增的兩種方法:auto_increment,identity(1,1)
下面介紹完整的創建一個表格的方式:舉例子說明
CREATE TABLE `fs_server` (
`id` int(11) NOT NULL auto_increment,
`server_id` int(11) NOT NULL,
`state` varchar(64) NOT NULL,
`check_time` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
如果不添加 PRIMARY KEY (`id`),則會導致報錯,需要添加一個關於主鍵的語句。

H. H2 Database 這個資料庫能用到真正的大型項目 生產環境嗎 , 一般java項目用到的內存資料庫用哪個呢

用來緩存消息的內存資料庫或Cache,需要滿足:
1.能快速方便的進行消息的查詢
2.能支持分布式 (網路模式)
3.能支持集群 (單點失效和負載均衡)
4. 支持持久化(自身能持久化, 不需要我們額外的開發)
SQLLite和Derby ,不過不是很確定這兩者是否都支撐集群,其他都支持,Derby是用純java寫的,集成在JDK6的安裝當中,現在叫JavaDB

I. 什麼是H2資料庫

H2是Thomas Mueller提供的一個開源的、純java實現的關系資料庫。

H2是一個開源的嵌入式資料庫引擎,採用java語言編寫,不受平台的限制,同時H2提供了一個十分方便的web控制台用於操作和管理資料庫內容。H2還提供兼容模式,可以兼容一些主流的資料庫,因此採用H2作為開發期的資料庫非常方便。

H2最大的用途在於可以同應用程序打包在一起發布,這樣可以非常方便地存儲少量結構化數據。

它的另一個用途是用於單元測試。啟動速度快,而且可以關閉持久化功能,每一個用例執行完隨即還原到初始狀態。

H2的第三個用處是作為緩存,作為NoSQL的一個補充。當某些場景下數據模型必須為關系型,可以拿它當Memcached使,作為後端MySQL/Oracle的一個緩沖層,緩存一些不經常變化但需要頻繁訪問的數據,比如字典表、許可權表。不過這樣系統架構就會比較復雜了。

(9)h2資料庫使用基於內存擴展閱讀:

H2資料庫運行方式:

1、內存模式

資料庫只在內存中運行,關閉連接後資料庫將被清空,適合測試環境,連接字元串:jdbc:h2:mem:DBName;DB_CLOSE_DELAY=-1,如果不指定DBName,則以私有方式啟動,只允許一個連接。

2、嵌入式

資料庫持久化存儲為單個文件。連接字元串:jdbc:h2:file:~/.h2/DBName;AUTO_SERVER=TRUE。~/.h2/DBName表示資料庫文件的存儲位置,如果第一次連接則會自動創建資料庫。

3、服務模式

H2支持三種服務模式:web server:此種運行方式支持使用瀏覽器訪問H2 Console。

CP server:支持客戶端/伺服器端的連接方式。

PG server:支持PostgreSQL客戶端。

J. 如何用Java代碼後台啟動H2資料庫的內存模式有知道的嗎

packagetest;

importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;

importorg.h2.tools.Server;

publicclassH2Demo{
privateServerserver;
privateStringport="9094";
privateStringdbDir="./h2db/sample";
privateStringuser="zhoujiang";
privateStringpassword="123456";

publicvoidstartServer(){
try{
System.out.println("正在啟動h2...");
server=Server.createTcpServer(
newString[]{"-tcpPort",port}).start();
}catch(SQLExceptione){
System.out.println("啟動h2出錯:"+e.toString());
//TODOAuto-generatedcatchblock
e.printStackTrace();
thrownewRuntimeException(e);
}
}

publicvoidstopServer(){
if(server!=null){
System.out.println("正在關閉h2...");
server.stop();
System.out.println("關閉成功.");
}
}

publicvoiseH2(){
try{
Class.forName("org.h2.Driver");
Connectionconn=DriverManager.getConnection("jdbc:h2:"+dbDir,
user,password);
Statementstat=conn.createStatement();
//insertdata
stat.execute("CREATETABLETEST(NAMEVARCHAR)");
stat.execute("INSERTINTOTESTVALUES('HelloWorld')");

//usedata
ResultSetresult=stat.executeQuery("selectnamefromtest");
inti=1;
while(result.next()){
System.out.println(i+++":"+result.getString("name"));
}
result.close();
stat.close();
conn.close();
}catch(Exceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}

publicstaticvoidmain(String[]args){
H2Demoh2=newH2Demo();
h2.startServer();
h2.useH2();
h2.stopServer();
System.out.println("==END==");
}
}