h2

How do you connect to H2 as a remote database instead of embedded mode using Spring Boot?

北城余情 提交于 2019-12-10 10:08:14
问题 I have this configuration under src/main/resources for my little Spring Boot application: server.port = 8090 spring.datasource.driverClassName = org.h2.Driver spring.datasource.url = jdbc:h2:file:~/stapler I know this configuration is picked up properly, cause there is valid port number 8090 in application startup log. There is also a @PostConstruct initDb() method which creates and inserts data into 2 tables of that database: package com.avk.stapler.init; import org.springframework.beans

Play! not shutting down H2 correctly

早过忘川 提交于 2019-12-10 03:54:16
问题 I'm using Play to write a webapp which is deployed in Tomcat. Because the app won't be processing very much data I'm using the default H2 database with Hibernate. When I want to deploy a new version of the app, I shut down tomcat, wipe the old webapp and WAR, add my new WAR, and start back up. This worked until a few days ago, when I added the database component. Now, I am often unable to redeploy the app. When I delete the old directory, it is automatically regenerated with this structure: $

Why does recreating H2 database reduce the size drastically

≡放荡痞女 提交于 2019-12-10 03:36:44
问题 I have a small database (6 tables, max rows of 70,000) which was taking up 16GB of disk space. I couldn't figure out why the size was so big. I tried running compact shutdown which actually increased the size by a few megabytes instead of reducing it. I tried deleting rows, which made almost no difference. Then I tried creating a script, dropping everything, re-creating the database from the script: SCRIPT TO 'mydb.sql'; DROP ALL OBJECTS; RUNSCRIPT FROM 'mydb.sql'; The size of the database

Unable to get results from H2 db

假如想象 提交于 2019-12-10 03:14:59
问题 I'm trying to get values from h2 db, but always getting this error org.h2.jdbc.JdbcSQLException: No data is available [2000-171] at org.h2.message.DbException.getJdbcSQLException(DbException.java:329) at org.h2.message.DbException.get(DbException.java:169) at org.h2.message.DbException.get(DbException.java:146) at org.h2.message.DbException.get(DbException.java:135) at org.h2.jdbc.JdbcResultSet.checkOnValidRow(JdbcResultSet.java:2956) at org.h2.jdbc.JdbcResultSet.get(JdbcResultSet.java:2962)

SQL (Java, h2): What's the best way to retrieve the unique ID of the single item I just inserted into my database? [duplicate]

两盒软妹~` 提交于 2019-12-10 01:13:59
问题 This question already has answers here : How to get the insert ID in JDBC? (12 answers) Closed 4 years ago . My current method is this: SELECT TOP 1 ID FROM DATAENTRY ORDER BY ID DESC This assumes the latest inserted item always has the highest unique ID (primary key, autoincrementing). Something smells wrong here. Alternatives? 回答1: If the JDBC driver supports it, you can also just use Statement#getGeneratedKeys() for that. String sql = "INSERT INTO tbl (col) VALUES (?)"; preparedStatement =

跨数据库查询:MySQL inner join PostgreSQL inner join ...

旧街凉风 提交于 2019-12-09 12:58:43
昨天重温 h2 database 的文档时,看到一个一直被我无视的命令 create linked table !仔细研究后发现这绝对是一个NB的功能:可实现跨不同类型数据库的连接查询! 按照官方文档的介绍, create linked table 可以创建一张表,链接到任何支持 JDBC 的外部数据库中的表。执行简单查询(无 join 语句)时,会自动将查询语句发送给外部数据库;如果有 join 语句,这查询语句会被自动翻译成相应的简单查询语句,再发送给外部数据库。 分库 例如, MySQL 中有用户表 users (id, name) , PostgreSQL 中有收藏夹表 favorites (id, user_id, name, link) 。要求查询获得 id 为 1 的用户名和收藏中所有的链接,通常需要分两步: 在 users 中查询 id 为 1 的记录; 在 favorites 中查询 user_id 的链接。 利用 linked table ,解决方案是: 先创建 users 表的映射,指定使用的 JDBC 驱动、地址、用户名、密码和表名。 再创建 favorites 表的映射,参数与#1相同。 通过 inner join 查询获得指定用户的名字与收藏夹中的链接。 create linked table users ('com.mysql.jdbc.Driver'

How to show content of local h2 database(web console)?

泄露秘密 提交于 2019-12-09 05:09:07
问题 Recently I joined a new team and here guys use h2 for stub service. I was wondering whether I can show the content of this database using web interface. At work it is available by going to localhost:5080 I have a project where I use h2 database, but I cannot see the h2 web console when I hit localhost:5080 I tried also localhost:8082 - it also doesn't work. My project configuration (works successfully): <bean id="wrappedDataSource" class="net.bull.javamelody.SpringDataSourceFactoryBean">

How to connect H2 console to embedded Spring H2 DB

旧街凉风 提交于 2019-12-09 03:50:50
问题 Ok, Im developing simple app, which has Spring Ebedded H2 database for development. database.xml bean conf looks like this: <bean id="h2Server" class="org.h2.tools.Server" factory-method="createTcpServer" init-method="start" destroy-method="stop" depends-on="h2WebServer"> <constructor-arg value="-tcp,-tcpAllowOthers,-tcpPort,9092" /> </bean> <bean id="h2WebServer" class="org.h2.tools.Server" factory-method="createWebServer" init-method="start" destroy-method="stop"> <constructor-arg value="

SQL query on H2 database table throws ArrayIndexOutOfBoundsException

穿精又带淫゛_ 提交于 2019-12-08 22:12:59
问题 I have a H2 database on which some queries work, while others are throwing an ArrayIndexOutOfBoundsException . For example: SELECT COLUMN_1 FROM MY_TABLE; // works fine SELECT COUNT(COLUMN_1) FROM MY_TABLE; // gives following error message: [Error Code: 50000, SQL State: HY000] General error: "java.lang.ArrayIndexOutOfBoundsException"; SQL statement: SELECT COUNT(COLUMN_1) FROM MY_TABLE [50000-167] What is the cause for this eror message? 回答1: The reason for the error message was a corrupt

H2 jdbc Connection refused: connect 90067-147

天涯浪子 提交于 2019-12-08 19:25:35
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(SessionRemote.java:271) at org.h2.engine.SessionRemote.createSession(SessionRemote.java:265) at org.h2