h2

Spring configuration for embedded H2 database for tests

不打扰是莪最后的温柔 提交于 2019-11-27 10:36:57
What does your Spring configuration for integration tests look like using an embedded h2 datasource and, optionally, JUnit? My first try with a SingleConnectionDataSource basically worked, but failed on more complicated tests where you need several connections at the same time or suspended transactions. I think h2 in tcp based server mode might work as well, but this is probably not the fastest communication mode for a temporary embedded database in memory. What are the possibilities and their advantages / disadvantages? Also, how do you create the tables / populate the database? Update: Let's

spring boot default H2 jdbc connection (and H2 console)

旧街凉风 提交于 2019-11-27 10:05:45
I am simply trying to see the H2 database content for an embedded H2 database which spring-boot creates when I don't specify anything in my application.properties and start with mvn spring:run. I can see hibernate JPA creating the tables but if I try to access the h2 console at the URL below the database has no tables. http://localhost:8080/console/ I see suggestions like this one: View content of embedded H2 database started by Spring But I don't know where to put the suggested XML in spring-boot and even if I did, I don't want the h2console to be available anymore when an external database

H2 database column name “GROUP” is a reserved word

不羁岁月 提交于 2019-11-27 09:44:42
How do I create a table in H2 with a column named GROUP? I saw an example that used something like [*] a while ago, but I can't seem to find it. Trailing Underscore Add a trailing underscore : GROUP_ The SQL spec explicitly promises † that no keyword will ever have a trailing underscore. So you are guaranteed that any naming you create with a leading or trailing underscore will never collide with a keyword or reserved word. I name all my columns, constraints, etc. in the database with a trailing underscore. Seems a bit weird at first, but you get used to seeing it. Turns out to have a nice

使用Spring Profile和Mybatis进行多个数据源(H2和Mysql)的切换

空扰寡人 提交于 2019-11-27 09:34:17
最近在做WebMagic的后台,遇到一个问题:后台用到了数据库,本来理想情况下是用Mysql,但是为了做到开箱即用,也整合了一个嵌入式数据库H2。这里面就有个问题了,如何用一套代码,提供对Mysql和H2两种方案的支持?博主收集了一些资料,也调试了很久,终于找到一套可行方案,记录下来。代码贴的有点多,主要是为了以后方便自己查找。 H2的使用 H2是一个嵌入式,纯Java实现的数据库,它各方面都要好于Java的sqlitejdbc。它可以使用内存模式,也可以使用磁盘模式。具体使用可以看攻略: http://www.cnblogs.com/gao241/p/3480472.html 为MyBatis同时配置两套数据源 我们希望达到的效果是,不同的数据源使用不同的sql,并且这个切换最好只在配置中体现,与代码无关。所以我们选择xml的方式编写sql语句。 MyBatis Spring的使用 同时使用Mybatis-Spring插件,这样Mybatis可以将Mapper(也就是DAO)自动配置成Bean,非常方便。它的一个完整示例可以看这个项目: https://github.com/mybatis/jpetstore-6 。这里我配置如下: 配置Bean <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

H2 Database vs SQLite on Android

三世轮回 提交于 2019-11-27 08:22:05
Because of the lack of Unicode support on the embedded SQLite database in Android I am mostly interested in performance and stability of H2 Database vs Android SQLite Are you guys using it? Should I be aware of any H2 database shortcomings? Things are much better than I have expected. I now have an Android phone (HTC Desire, Android 2.2) and I made a first test. Opening and closing a database is relatively slow so far (opening an existing database for the second time takes 0.2 seconds, closing about 0.2 seconds), but otherwise it looks like H2 performs quite well on Android, even if the Dalvik

Do databases always lock non-existent rows after a query or update?

大憨熊 提交于 2019-11-27 07:31:09
问题 Given: customer[id BIGINT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(30), count INT] I'd like to execute the following atomically: Update the customer if he already exists; otherwise, insert a new customer. In theory this sounds like a perfect fit for SQL-MERGE but the database I am using doesn't support MERGE with AUTO_INCREMENT columns. https://stackoverflow.com/a/1727788/14731 seems to indicate that if you execute a query or update statement against a non-existent row, the database will

Timeout error trying to lock table in h2

夙愿已清 提交于 2019-11-27 07:04:10
I get the following error under a certain scenario When a different thread is populating a lot of users via the bulk upload operation and I was trying to view the list of all users on a different web page. The list query, throws the following timeout error. Is there a way to set this timeout so that I can avoid this timeout error. Env: h2 (latest), Hibernate 3.3.x Caused by: org.h2.jdbc.JdbcSQLException: Timeout trying to lock table "USER"; SQL statement: [50200-144] at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) at org.h2.message.DbException.get(DbException.java:167)

How to find rows in one table that have no corresponding row in another table

扶醉桌前 提交于 2019-11-27 06:51:55
I have a 1:1 relationship between two tables. I want to find all the rows in table A that don't have a corresponding row in table B. I use this query: SELECT id FROM tableA WHERE id NOT IN (SELECT id FROM tableB) ORDER BY id desc id is the primary key in both tables. Apart from primary key indices, I also have a index on tableA(id desc). Using H2 (Java embedded database), this results in a full table scan of tableB. I want to avoid a full table scan. How can I rewrite this query to run quickly? What index should I should? select tableA.id from tableA left outer join tableB on (tableA.id =

Generate UUID values by default for each row on column of UUID type in H2 Database Engine

让人想犯罪 __ 提交于 2019-11-27 06:21:05
问题 In the H2 database, on a table with a column of UUID data type, how do we specify that we want H2 to generate a UUID value by default when an INSERT omits that field? I know how to generate a UUID. I have read the Question, How to insert a specific UUID in h2 database?. My question is about how to ask H2 to generate the UUID value on my behalf. 回答1: You can use built-in function RANDOM_UUID(): create table test(id int primary key, data uuid default random_uuid()); insert into test(id) values

Why we need a connection pooling for JDBC? [closed]

吃可爱长大的小学妹 提交于 2019-11-27 05:40:34
问题 What are the benefits of using a JDBC connection pooling tool like DBCP or c3p0 ? in case of a small CRUD application with one user, can we just create one connection session as a singleton ? PS : I'm building a small javafx application back-ended with tiny h2 database (5 tables). 回答1: From Jon Skeet's answer to What is the benefit of Connection and Statement Pooling?: Creating a network connection to a database server is (relatively) expensive. Likewise asking the server to prepare a SQL