h2

H2 in-mem-DB with hibernate set to create giving me table not found errors

醉酒当歌 提交于 2019-12-21 04:53:18
问题 I wanted to set up a project with hibernate, spring mvc and H2 as (for now) in memory DB. When everything boots up (in jetty) I get errors saying that the tables aren't yet present. This is the error I get: Okt 09, 2013 3:42:47 PM org.hibernate.tool.hbm2ddl.SchemaExport execute INFO: HHH000227: Running hbm2ddl schema export Okt 09, 2013 3:42:47 PM org.hibernate.tool.hbm2ddl.SchemaExport perform ERROR: HHH000389: Unsuccessful: alter table PUBLIC.Object drop constraint FK

How to find the active number of open database connections in H2/MySQL

ぐ巨炮叔叔 提交于 2019-12-21 04:50:10
问题 How to find the active number of open database connections in H2/MySQL. We need this information to identify if there are any connection leaks. 回答1: For H2, use: select * from information_schema.sessions; For MySQL, use: show full processlist; or select * from information_schema.processlist; If you are just interested in the session count, use select count(*) instead of select * 来源: https://stackoverflow.com/questions/6137683/how-to-find-the-active-number-of-open-database-connections-in-h2

Make H2 treat quoted name and unquoted name as the same

早过忘川 提交于 2019-12-21 03:36:15
问题 H2 seems to make a difference between name with quote and name without quote. Is there a way to make it treat them the same way? Here's the tests that I've done : CREATE TABLE test (dummy INT); CREATE TABLE "testquote" (dummy INT, "quotedDummy" INT); Here are the queries : SELECT * FROM test; --work SELECT * FROM "test"; -- doesn't work SELECT * FROM "testquote"; --work SELECT * FROM testquote; --doesn't work SELECT dummy FROM "testquote"; --work SELECT quotedDummy FROM "testquote"; --doesn't

Embedding an H2 Database within the WEB-INF Directory

橙三吉。 提交于 2019-12-21 02:42:49
问题 I have an embedded H2 Database I'd like to put in the WEB-INF directory of a web application. What is the proper way to refer to this in a JDBC url? Ideally I'd like a solution that would work both for a WAR, and an expanded WAR (If possible). Thank-you for your help! FYI, I've tried the following: jdbc:h2:/WEB-INF/data/myDB;CIPHER=AES But this results in: org.h2.jdbc.JdbcSQLException: A file path that is implicitly relative to the current working directory is not allowed in the database URL

Setup H2 in Server Mode using Java Based Configuration

不问归期 提交于 2019-12-20 14:45:35
问题 I have spring XML that enables me to start H2 database in server mode using the following configuration: <beans profile="test-h2"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="org.h2.Driver"/> <property name="url" value="jdbc:h2:target/h2/pps;AUTO_SERVER=TRUE"/> <property name="username" value="sa"/> <property name="password" value=""/> </bean> <bean id="entityManagerFactory" parent=

Package and use embedded database (H2.db file) inside a Jar?

≯℡__Kan透↙ 提交于 2019-12-20 14:41:48
问题 I'm using H2 embedded database for my application. I would like to contain everything the application needs in it's own Jar, including it's database if possible. My app does not need to create temp files or anything, so basically the user just runs the Jar. Is it possible to embed a database inside a Jar, and be able to INSERT new records as well as just SELECT out? EDIT: Just to clarify, I'm not looking to embed the H2 driver jar inside my distributable jar, I'm looking to embed the h2

Performance issues using H2 DB in embedded mode with heavy load of data in database

风格不统一 提交于 2019-12-20 10:47:13
问题 I am working a java application using H2 Database in embedded mode. My Application consumes 150mb of heap memory. Problem: Steps When I load H2 database with 2 mb of data, database access is fast and heap memory size 160mb. But When I load H2 database with 30 mb of data(h2 db file size =30 mb). Then accessing the database from my application is very slow. the reason being my application heap size is hugely grown to 300mb of size hence degraded performance. I confirmed using JConsole. So my

org.hibernate.PersistentObjectException: detached entity passed to persist with H2 in memory database

喜你入骨 提交于 2019-12-19 19:54:30
问题 i am using H2 in memory database for testing and my configuration is as follows: 1- SpringTestingConfig: @Configuration @ComponentScan(basePackages = "com.myapp.data", excludeFilters = { @Filter(Configuration.class) }) @PropertySource("classpath:/test.properties") @Profile("test") public class SpringTestingConfig { @Bean public DataSource dataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("org.h2.Driver"); dataSource.setUrl("jdbc

How to get start and end dates of current month

走远了吗. 提交于 2019-12-19 11:34:32
问题 How to get start date and end dates in a query from database. Thanks, Lico 回答1: http://sqltutorials.blogspot.com/2007/06/sql-first-and-last-day-of-month.html Only thing that isn't covered is how to retrieve the current date... see rexem's post. 回答2: CURRENT_DATE[()] | CURDATE() | SYSDATE | TODAY = returns current date Start of month: DATE EXTRACT(YEAR FROM SYSDATE) +'-'+ EXTRACT(MONTH FROM SYSDATE) +'-01' 回答3: For completeness, start of month: DATE EXTRACT(YEAR FROM SYSDATE) +'-'+ EXTRACT

Cannot call trigger in H2 DB

自古美人都是妖i 提交于 2019-12-19 10:59:06
问题 I tried run a simple class to call TRIGGER from Java code, I used H2 DB, can you help me? Here is my simple code (like sample code in H2): public class TriggerTest { public static void main(String[] args) throws Exception { System.out.println(TriggerTest.MyTrigger.class.getName()); Class.forName("org.h2.Driver"); Connection conn = DriverManager.getConnection("jdbc:h2:tcp://localhost/~/chap1", "sa", "sa"); Statement stat = conn.createStatement(); stat.execute("Drop Table if exists INVOICE");