h2

Does H2 support the serializable isolation level?

∥☆過路亽.° 提交于 2019-12-07 02:49:07
问题 Wikipedia describes the Phantom read phenomenon as: A phantom read occurs when, in the course of a transaction, two identical queries are executed, and the collection of rows returned by the second query is different from the first. It also states that with serializable isolation level, Phantom reads are not possible. I'm trying to make sure it is so in H2, but either I expect the wrong thing, or I do a wrong thing, or something is wrong with H2. Nevertheless, here's the code: try(Connection

Connecting to H2 server from DbVisualizer

隐身守侯 提交于 2019-12-06 23:09:56
问题 I have configured my H2 database as follows: @Configuration @Profile({ Profiles.DEV }) public class DevDataSourceConfiguration { @Bean(initMethod = "start", destroyMethod = "stop") public Server h2WebServer() throws SQLException { return Server.createWebServer("-web", "-webAllowOthers", "-webPort", "8082"); } @Bean(initMethod = "start", destroyMethod = "stop") @DependsOn("h2WebServer") public Server h2Server() throws SQLException { return Server.createTcpServer("-tcp", "-tcpAllowOthers", "

“Create table if not exists” - how to check the schema, too?

匆匆过客 提交于 2019-12-06 19:14:30
问题 Is there a (more or less) standard way to check not only whether a table named mytable exists, but also whether its schema is similar to what it should be? I'm experimenting with H2 database, and CREATE TABLE IF NOT EXISTS mytable (....) statements apparently only check for the table´s name . I would expect to get an exception if there's a table with the given name, but different schema. 回答1: CREATE TABLE IF NOT EXISTS ... is not a standard SQL code. The thing to do is to check if the table

Defining a Foreign key constraint in H2 Databases

谁说胖子不能爱 提交于 2019-12-06 18:21:54
问题 I am new in coding so I made a tables in SQL server and it worked, so i used the same command in H2 and it said I have a syntax problems with the second table, someone can help? CREATE TABLE TOURISTINFO( TOURISTINFO_ID INT PRIMARY KEY, NAME VARCHAR(25) NOT NULL, NATIONALITY VARCHAR(15) NOT NULL ) CREATE TABLE PLANETICKETS( DESTINATION VARCHAR(10) NOT NULL, TICKETPRICE NUMERIC(8,2) NOT NULL, TOURISTINFO_ID INT FOREIGN KEY REFERENCES TOURISTINFO ) The error is Syntax error in SQL statement

org.h2.jdbc.JdbcSQLException: The object is already closed

♀尐吖头ヾ 提交于 2019-12-06 16:34:12
For the life of me I cannot see how it "is already closed" import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class RsetTest2 { public static void main(String[] args) throws Exception { String dbpath = "jdbc:h2:c:/mydb;IFEXISTS=TRUE;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE"; Connection conn = null; System.setProperty("h2.bindAddress", "127.0.0.1"); Class.forName("org.h2.Driver"); conn = DriverManager.getConnection(dbpath, "sa", "sa"); conn.setAutoCommit(false); System.out.println("success. querying database for latest values..

MERGE INTO table containing AUTO_INCREMENT columns

跟風遠走 提交于 2019-12-06 16:09:39
I've declared the following table for use by audit triggers: CREATE TABLE audit_transaction_ids (id IDENTITY PRIMARY KEY, uuid VARCHAR UNIQUE NOT NULL, `time` TIMESTAMP NOT NULL); The trigger will get invoked multiple times in the same transaction. The first time the trigger is invoked, I want it to insert a new row with the current TRANSACTION_ID() and time. The subsequent times the trigger is invoked, I want it to return the existing "id" (I invoke Statement.getGeneratedKeys() to that end) without altering "uuid" or "time". The current schema seems to have two problems. When I invoke MERGE

Oracle sql developer - export DDL - only create table sql

a 夏天 提交于 2019-12-06 16:09:21
I want to run unit tests by generating all tables in HSQLDB, present in my oracle database. For that I want to export all DDL create table statements from oracle tables. I tried export database, but along with create table sql I am getting lot other SQLs like, " PARTITION BY RANGE ("CREATION_DATE") " etc. How do I export all oracle tables(schema) to HSQLDB? is there any better way? You can use the DBMS_METADATA.GET_DDL() function to get the table definition, and modify what is included with the SET_TRANSFORM_PARAM() options, specifically in this case the PARTITIONING parameter. There are lots

Spring tests are closing embedded database multiple times

与世无争的帅哥 提交于 2019-12-06 11:52:17
问题 I am using h2 embedded database which is defined like that: <jdbc:embedded-database id="embeddedDatasource" type="h2"/> And I have two tests: @RunWith(SpringJunit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration("classpath:h2-context.xml") class Test1 {...} @RunWith(SpringJunit4ClassRunner.class) @ContextConfiguration("classpath:h2-context.xml") class Test2 {...} After all tests execution I do see in the log: * Closing org.springframework.context.support.GenericApplicationContext

Selecting random rows from a big table in H2 database

吃可爱长大的小学妹 提交于 2019-12-06 11:24:28
I have a big table in my database (potentially millions of records) and I need to select #X random rows (let's say #X between 10 and 50) , but I need this query to be as optimal as possible. The table looks like this: CREATE TABLE sample ( id bigint auto_increment PRIMARY KEY, user_id bigint NOT NULL, screen_name VARCHAR NOT NULL, ... ); I've searched around and I found answers like this: SELECT * FROM sample ORDER BY RAND() limit X. But It looks to me that this will fetch the full table then sort it, isn't it? I think it would be best to generate 10 or 50 random integers and do a select *

How do I determine if an H2 database file lock exists?

你。 提交于 2019-12-06 11:06:25
问题 For reasons that I will not explain (because people will direct their responses at the other topic, instead of my problem at hand), I need to know how to determine whether or not my H2 database is locked. Using Java code, how do I determine whether or not the lock file exists on my database? 回答1: For others reading this question I need to explain why you you shouldn't do it yourself, and let the database detect itself whether it is locked or not. First of all, database file locking is an