由于以下配置,我想在Web浏览器中查看Spring启动的H2数据库的内容:
<jdbc:embedded-database id="dataSource" type="H2" />
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="classpath:db/populateDB.sql"/>
</jdbc:initialize-database>
Run Code Online (Sandbox Code Playgroud)
我在日志中搜索了JDBC URL:
DEBUG o.s.j.d.SimpleDriverDataSource - Creating new JDBC Driver Connection to [jdbc:h2:mem:dataSource;DB_CLOSE_DELAY=-1]
Run Code Online (Sandbox Code Playgroud)
所以我可以填写连接表格如下:

但不幸的是,db仍然是空的,而不应该是由于populateDB.sql脚本.
任何的想法?
谢谢!
我们在内存中使用hdsqldb来运行针对数据库运行的junit测试.在通过弹簧配置运行每个测试之前设置db.一切正常.现在,当测试失败时,可以方便地检查内存数据库中的值.这可能吗?如果是这样的话?我们的网址是:
jdbc.url = JDBC:HSQLDB:MEM:TESTDB; sql.enforce_strict_size =真
每次测试后都会销毁数据库.但是当调试器运行时,数据库也应该仍然存在.我尝试连接sqldb databaseManager.这工作,但我没有看到任何表或数据.任何帮助都非常感谢!
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http:// www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="test" class="com.Test">
<constructor-arg>
<list>
<value>aa</value>
<value>bb</value>
<value>cc</value>
</list>
</constructor-arg>
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
这是我目前的XML.如果Test只拿一份清单 - 一切都会好的.
问题是Test需要一个字符串数组.
怎么在春天做?
我在servlet上下文启动时通过以下代码在H2数据库中创建一个内存数据库
void initDb() {
try {
webserver = Server.createWebServer().start();
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1","SA","");
InputStream in = getClass().getResourceAsStream("script.sql");
if (in == null) {
System.out.println("Please add the file script.sql to the classpath, package " + getClass().getPackage().getName());
} else {
RunScript.execute(conn, new InputStreamReader(in));
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT TO_CHAR(bday,'DD/MM/yyyy hh24:mi') FROM TEST2");
while (rs.next()) {
System.out.println(rs.getString(1));
}
rs.close();
stat.close();
conn.commit();
conn.close();
}
//accessed using url jdbc:h2:tcp://localhost/mem:db1
try{
CachedRowSet crs = new DBConnector().executeQuery("select * from test2");
while(crs.next()){
System.out.println("ARGUMENT_NAME:"+crs.getString(1));
// System.out.println(",DATA_TYPE:"+crs.getString("DATA_TYPE")); …Run Code Online (Sandbox Code Playgroud) I have a Grails app which works fine when using the default embedded H2 database. Now I'd need to run some tests where I need more integrated environment, so I thought of using H2 in server mode for this and making my other apps access the same DB.
I start the H2 server from command line and get tcp://192.168.56.1:9092 for the server URL. I've set it in Grails datasource as jdbc:h2:tcp://localhost:9092/~/devDb;IFEXISTS=TRUE.
Once I start the Grails app, it simply …
I have used the below settings in my Application properties file. But still cant see my tables in h2 console.
application.properties
logging.level.org.springframework.web=INFO
spring.datasource.url=jdbc:h2:mem:challenge;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MV_STORE=FALSE
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.schema=classpath:/schema.sql
spring.datasource.data=classpath:/data.sql
spring.h2.console.enabled=true
spring.h2.console.path=/h2
server.port = 8080
Run Code Online (Sandbox Code Playgroud)
I used the string jdbc:h2:mem:challenge;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MV_STORE=FALSE in the JDBC URL on H2 console to login. Yet i am not seeing any tables
The below is my Graddle file
buildscript {
ext {
springBootVersion = '1.4.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: …Run Code Online (Sandbox Code Playgroud)