java - Doesn't show H2 tables in browser -
hello,
i have problem displaying h2 tables in browser i've created on java web application ( spring 4, hibernate 5, thymeleaf 3, h2database 1.4.192 , etc.). has java-based configuration.
my datasource:
@bean(name = "datasource") public datasource getdatasource() { logger.info("setting datasource properties."); embeddeddatabasebuilder builder = new embeddeddatabasebuilder(); embeddeddatabase embeddeddatabase = builder .continueonerror(true) .settype(embeddeddatabasetype.h2) .addscript(create_script) .addscript(init_script) .build(); return embeddeddatabase; }
my 'create_script':
create table clients ( client_id int primary key auto_increment, client_name varchar(99) not null, agreement boolean default false ); create table items ( item_id int primary key auto_increment, item_name varchar(99) not null, price decimal(10,2) not null ); create table clients_items ( client_id int , item_id int not null, constraint clients_client_id_fk foreign key (client_id) references clients(client_id), constraint items_item_id_fk foreign key (item_id) references items (item_id) );
my 'init_script':
insert items (item_name, price) values ('book', 5.50); insert items (item_name, price) values ('hook', 15.00); insert items (item_name, price) values ('nook', 199.9); insert items (item_name, price) values ('snook', 1.9); insert items (item_name, price) values ('stook', 0.99); insert items (item_name, price) values ('mobile phone', 10);
the tables created 100% cuz can persist , fetch data.
ноя 10, 2016 11:15:59 org.springframework.jdbc.datasource.embedded.embeddeddatabasefactory initdatabase
> info: starting embedded database: url='jdbc:h2:mem:testdb;db_close_delay=-1;db_close_on_exit=false', username='sa'
ноя 10, 2016 11:15:59 org.springframework.jdbc.datasource.init.scriptutils executesqlscript
info: executing sql script class path resource [create.sql]
ноя 10, 2016 11:15:59 org.springframework.jdbc.datasource.init.scriptutils executesqlscript
info: executed sql script class path resource [create.sql] in 479 ms.
ноя 10, 2016 11:15:59 org.springframework.jdbc.datasource.init.scriptutils executesqlscript
info: executing sql script class path resource [test.sql]
ноя 10, 2016 11:15:59 org.springframework.jdbc.datasource.init.scriptutils executesqlscript
info: executed sql script class path resource [test.sql] in 11 ms.
ноя 10, 2016 11:16:09 org.springframework.orm.hibernate5.hibernatetransactionmanager afterpropertiesset
info: using datasource [org.springframework.jdbc.datasource.embedded.embeddeddatabasefactory$embeddeddatasourceproxy@162b3d47] of hibernate sessionfactory hibernatetransactionmanager
but when open h2-console , connect database current username , password can find nothing.
it's strange , don't know problem is. me please.
thank much.
the problem create in-memory database
jdbc:h2:mem:testdbnot persistent , cannot connect via web console.
see: http://www.h2database.com/html/features.html#in_memory_databases
depending want do
- perist data --> use file based local h2 database
- keep in-memory --> maybe so answer solution
Comments
Post a Comment