h2

H2 database, insert by selecting results from CSVREAD

别说谁变了你拦得住时间么 提交于 2019-12-08 19:13:52
问题 I have a CSV file like 1,hello,13 2,world,14 3,ciao,26 I'm trying to use CSVREAD function to read this file into database, like this insert into my_table( id, message, code ) values ( select convert( "id",bigint ), "message", convert( "code", bigint) from CSVREAD( 'myfile.csv', 'id,message,code', null ) ); For some reason I keep on getting SQL error stating that the column count does not match. The table is created with Hibernate/GORM and contains the fields I try to insert into. The select

Why I can't get the org.h2.Driver? I use maven

ぃ、小莉子 提交于 2019-12-08 15:00:13
问题 I face a problem about connecting to H2 this is my pom.xml: <project> <modelVersion>4.0.0</modelVersion> <groupId>.</groupId> <artifactId>dbConnection</artifactId> <name>Db Connection</name> <packaging>war</packaging> <version>0.1</version> <dependencies> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.3.176</version> </dependency> </dependencies> </project> and this is my main code import java.sql.*; public class DbConnection { static final String DB_URL

Insert into h2 table if not exists

本小妞迷上赌 提交于 2019-12-08 14:48:59
问题 I am using H2. I want to insert a value into a table if it does not exist. I create the table with: CREATE TABLE IF NOT EXISTS $types (type VARCHAR(15) NOT NULL UNIQUE); And I want to do something like REPLACE INTO types (type) values ('type1'); I found an example about Replace that apparently works for MySQL but I am using h2. But I get an error when I run this from my h2 console: Syntax error in SQL statement "REPLACE[*] INTO TYPES (TYPE) VALUES ('expense') "; expected "ROLLBACK, REVOKE,

How can I setup my environment to use h2 for tests and mysql for development?

帅比萌擦擦* 提交于 2019-12-08 13:00:35
I'm using the default configuration for the yo jhipster generator except that I'm using mysql as my "dev" database. When I run mvn test my tests succeed with no failures. However, I found that if I ran tests a second time, the suite would fail since it would run against the "dev" database...that wasn't 'rolled back' or 'reset' after the previous test run. I would rather have expected it to run against an in-memory h2 database as configured in src/test/resources/config/application.yml that would be reset after each run. How can I setup my environment with h2 for tests and mysql for development?

Custom queries in Spring with JPA

大城市里の小女人 提交于 2019-12-08 12:24:54
问题 I have created a webapp similiar to the tutorial here: https://spring.io/guides/tutorials/react-and-spring-data-rest/ . I have added postgresql db and everything works fine. I have a basic query findByUsername(String name) in my repository which works fine. My problem is, I am for some reason unable to create custom queries e.g "SELECT CURRENT_TIMESTAMP" . Lets say i make a test where I just want to get the value of this statement. And by unable I mean I don't know how :) My google results

h2 database unit test across multiple schema

时光毁灭记忆、已成空白 提交于 2019-12-08 08:26:54
问题 I am trying to use unit test along with h2 database. My application uses MSSQL database. And below are the 2 table that am using in my application: SchemaA.dbo.Table1<br> SchemaB.dbo.table2<br> @Entity<br> @Table(name="SchemaB..table")<br> Class A <br> { private Long id; ............ } I am trying to write unit test to test the persistance of the above class. But h2 database does not recognise this tablename syntax: SchemaB..table Note : the 2 dots between schema name and table name. Any

MERGE INTO table containing AUTO_INCREMENT columns

ぃ、小莉子 提交于 2019-12-08 08:19:50
问题 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)

glassfish and h2database problem

牧云@^-^@ 提交于 2019-12-08 07:40:42
问题 I build an java based app. using hibernate JPA, spring and h2database. I using h2database in memory mode, here is the jdbc properties: jdbc.url=jdbc\:h2\:mem\:test_db;DB_CLOSE_DELAY\=-1 jdbc.driverClassName=org.h2.Driver jdbc.username=sa jdbc.password= This values I'm using in dataSource.xml like this: <bean id="basicDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value

H2 jdbc Connection refused: connect 90067-147

随声附和 提交于 2019-12-08 07:32:58
问题 I got a project to upgrade and it is using h2 DB with jdbc driver. During the build I have a systematic error on connection: Exception in thread "main" org.h2.jdbc.JdbcSQLException: Connection is broken: "Connection refused: connect" [90067-147] at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) at org.h2.message.DbException.get(DbException.java:156) at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:380) at org.h2.engine.SessionRemote.connectEmbeddedOrServer

H2 createTcpServer() does not create server?

牧云@^-^@ 提交于 2019-12-08 07:08:59
问题 after reading the H2 documentation, I wrote this simple application to create a H2 database in a local directory: public static void main(String[] args) throws SQLException { String path = "C:/Temp/H2/"; File fpath = new File(path); fpath.mkdirs(); FileUtils.recursiveDelete(fpath); String dbName = "tata"; String connection = "jdbc:h2:file:" + path + dbName; Server server = Server.createTcpServer(connection); server.start(); server.stop(); } This program runs fine, but when I check in the