16 Ocak 2023 Pazartesi

H2 Veri Tabanı Kullanımı

Docker
Şöyle yaparız
docker pull jesperdj/h2 # This command starts a new H2 container in detached mode (-d), # maps the container's 8082 and 9092 ports to the same ports on the host machine (-p), # and gives the container a name (-name). docker run -d -p 8082:8082 -p 9092:9092 --name h2 jesperdj/h2 # Open browser http://localhost:8082 # To log in to the H2 database, enter the following information on the login page: Driver Class: org.h2.Driver JDBC URL: jdbc:h2:mem:testdb User Name: sa Password: (leave this field blank)
Bir örnekte te burada

Sütun Tipleri
Şöyle
BOOLEAN: A Boolean column can store true or false values.

TINYINT: A TINYINT column can store a small integer value between -128 and 127.

SMALLINT: A SMALLINT column can store an integer value between -32,768 and 32,767.

INT: An INT column can store a larger integer value between -2,147,483,648 and 2,147,483,647.

BIGINT: A BIGINT column can store a very large integer value between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807.

DECIMAL: A DECIMAL column can store a fixed-point decimal value with a specified precision and scale.

FLOAT: A FLOAT column can store a floating-point value with single precision.

DOUBLE: A DOUBLE column can store a floating-point value with double precision.

DATE: A DATE column can store a date value.

TIME: A TIME column can store a time value.

TIMESTAMP: A TIMESTAMP column can store a date and time value.

BLOB: A BLOB column can store binary data, such as images or documents.

CLOB: A CLOB column can store large text data, such as XML or HTML.

TEXT 
Açıklaması şöyle
H2 supports a TEXT column type, which can be used to store large amounts of character data in a table. The TEXT type is used to store strings of up to 2^31-1 bytes (approximately 2GB) in size.
Örnek
Şöyle yaparız
CREATE TABLE my_table (
    id INT PRIMARY KEY,
    my_text_column TEXT
);
INSERT INTO my_table (id, my_text_column) VALUES (1, 'This is some text data.');
SELECT * FROM my_table;

Web Konsol
Şöyle yaparız
http://localhost:8082/
Bağlantı bilgileri
Saved Settings:	Generic H2 (Embedded)
Setting Name:	Generic H2 (Embedded)
  
Driver Class:	org.h2.Driver
JDBC URL:	 jdbc:h2:my-db-name
User Name:	sa
Password:
CREATE DATABASE Cümlesi
H2 bunu desteklemez. JDBC URL ile verilen veri tabanını otomatik yaratır, ancak bir veri tabanı içinden yeni bir veri tabanı yaratılmasına izin vermez.

MERGE Cümlesi
Söz dizimi şöyle
MERGE INTO tableName [ ( columnName [,...] ) ] 
[ KEY ( columnName [,...] ) ] 
{ VALUES { ( { DEFAULT | expression } [,...] ) } [,...] | select } 
Örnek
Şöyle yaparız
CREATE TABLE customer (
  id NUMBER, 
  name VARCHAR(20), 
  age NUMBER, 
  address VARCHAR(20), 
  salary NUMBER,
  PRIMARY KEY (id)
);

INSERT INTO customer (id,name,age,address,salary)
VALUES (1, 'orcun', 47, 'ankara', 2000);

MERGE INTO customer (id,name,age,address,salary)
KEY (id) VALUES (1, 'Colak', 46, 'istanbul', 2500);




Hiç yorum yok:

Yorum Gönder