h2

H2 SQL database - INSERT if the record does not exist

浪子不回头ぞ 提交于 2019-12-01 04:16:21
I would like initialize a H2 database, but I am not sure if the records exist. If they exist I don't want to do anything, but if they don't exist I would like to write the default values. Something like this: IF 'number of rows in ACCESSLEVELS' = 0 INSERT INTO ACCESSLEVELS VALUES (0, 'admin'), (1, 'SEO'), (2, 'sales director'), (3, 'manager'), (4, 'REP') ; The following works for MySQL, PostgreSQL, and the H2 database: drop table ACCESSLEVELS; create table ACCESSLEVELS(id int, name varchar(255)); insert into ACCESSLEVELS select * from ( select 0, 'admin' union select 1, 'SEO' union select 2,

How to embed H2 database into jar file delivered to the client?

别说谁变了你拦得住时间么 提交于 2019-12-01 03:45:09
问题 I use H2 database for a desktop application in embedded mode. When I compress the application into jar file the database file is omitted. So, when I run MyApplication.jar nothing works. What is the correct way to embed/include/connect h2.jar file with MyApplication.jar? Or maybe there is another way to deliver database and application in the bundle? 回答1: One common scheme is to put h2.jar in a lib directory relative to your application and include a Class-Path entry in your JAR's manifest

Oracle MERGE statement in H2 database

依然范特西╮ 提交于 2019-12-01 03:31:07
We started to use the H2 in memory database for automated testing. We use Oracle for our production & dev environments. So the idea is to duplicate the table structure in H2 test-database as it is in our Oracle dev-database. The Oracle SQL statements include MERGE statements and use alias for table names and USING in the query. How can I modify this query dynamically to be compatible with H2 in a way that it does not alter the existing query in the dev environment? Example of the Oracle SQL, to be made compatible with H2, MERGE INTO TABLE T1 USING ( SELECT .... ........... FROM DUAL) T2 (T1 &

Using H2 database server how to notify changes to clients (JMS messaging)

坚强是说给别人听的谎言 提交于 2019-12-01 02:34:08
I am successfully using H2 database in AUTO_SERVER mode so that a database file is shared among a number of desktop clients on a network transparently. This way a server is elected among the clients and all other clients read from the tcp server. What I'm missing is how a client or the server can notify all other desktop clients something has been changed in the database. Right now I'm using a JGroups channel to let all clients comunicate one with each other however this is another point of failure and another leader election algorithm which runs in parallel with H2. Isn't there any other

How to write a null safe compare “<=>” in pure SQL?

做~自己de王妃 提交于 2019-12-01 01:54:37
问题 In Mysql there is a compare operator that is a null safe: <=>. I use this in my Java program when creating prepared statements like this: String routerAddress = getSomeValue(); String sql = "SELECT * FROM ROUTERS WHERE ROUTER_ADDRESS <=> ? "; PreparedStatement stmt = connection.prepareStatement(sql); stmt.setString(1, routerAddress); Now I would like to switch to the H2 database. How do I write the <=> operator in pure SQL (using for example IS NULL and IS NOT NULL)? I would like use the stmt

Resetting autoincrement in h2

≯℡__Kan透↙ 提交于 2019-12-01 01:44:45
问题 I'm testing a controller that returns a json response but the tests fail after the first time because the h2 database does not reset the auto increment id. Using fixtures or creating objects manually has a same problem. @Before public void setUp() { Fixtures.deleteAllModels(); Fixtures.loadModels("data.yaml"); } How to solve this problem? 回答1: Start your play app, fire up browser with this url (if you run play app locally): http://localhost:9000/@db Enter your h2 db, and type the command

H2 SQL database - INSERT if the record does not exist

牧云@^-^@ 提交于 2019-12-01 00:57:33
问题 I would like initialize a H2 database, but I am not sure if the records exist. If they exist I don't want to do anything, but if they don't exist I would like to write the default values. Something like this: IF 'number of rows in ACCESSLEVELS' = 0 INSERT INTO ACCESSLEVELS VALUES (0, 'admin'), (1, 'SEO'), (2, 'sales director'), (3, 'manager'), (4, 'REP') ; 回答1: The following works for MySQL, PostgreSQL, and the H2 database: drop table ACCESSLEVELS; create table ACCESSLEVELS(id int, name

【消息队列】y.kafka单机安装

你说的曾经没有我的故事 提交于 2019-12-01 00:22:26
简介 要配置kafka,首先要配置zookeeper保证集群的高可用。因此本教程包含两者的配置。 http://kafka.apache.org/ 1、下载kafka: https://www.apache.org/dyn/closer.cgi?path=/kafka/2.1.0/kafka_2.11-2.1.0.tgz 2、下载zookeoper: http://mirror.bit.edu.cn/apache/zookeeper/ 百度云盘也放的有一份哦。 0、准备工作 1、目前配置是单机环境。 2、配置好本机的SSH无秘钥登录(虽然不是必须,但是作为集群间更好的管理,这是必要的步骤) 3、关闭防火墙。当然,为了安全起见,最好还是不要偷懒,应该针对性的开启需要开启的端口。 4、配置java jdk环境。 1、安装zookeeper 1、解压安装包并复制zoo.cfg模板文件为zoo.cfg # cd /opt/module/zookeeper-3.4.10/conf # cp zoo_sample.cfg zoo.cfg 2、配置zoo.cfg # vi zoo.cfg zoo.cfg配置如下: #心跳间隔 tickTime=2000 #其他服务器连接到Leader时,最长能忍受的心跳间隔数:10*2000 = 20秒 initLimit=10 #发送消息时,多长忍受心跳间隔数

Oracle MERGE statement in H2 database

自闭症网瘾萝莉.ら 提交于 2019-12-01 00:20:05
问题 We started to use the H2 in memory database for automated testing. We use Oracle for our production & dev environments. So the idea is to duplicate the table structure in H2 test-database as it is in our Oracle dev-database. The Oracle SQL statements include MERGE statements and use alias for table names and USING in the query. How can I modify this query dynamically to be compatible with H2 in a way that it does not alter the existing query in the dev environment? Example of the Oracle SQL,

h2 does not enforce NOT NULL in MySQL compatibility mode

不问归期 提交于 2019-12-01 00:02:53
问题 In MySQL compatibility mode, the following SQL succeeds and returns 0: CREATE TABLE test2 (i INTEGER NOT NULL); INSERT INTO test2 VALUES (NULL); SELECT * FROM test2; It fails as expected in the default mode. It also fails with MySQL 5.5 / InnoDB. Does "MySQL compatibility" actually mean "MyISAM compatibility"? 回答1: This problem is due to both the way MySQL handles Null values and h2 . Basically MySQL converts nulls received to empty string/0 where as in h2 there is clear distinction among all