相关疑难解决方法(0)

查看Spring启动的嵌入式H2数据库的内容

由于以下配置,我想在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脚本.

任何的想法?

谢谢!

spring h2

47
推荐指数
5
解决办法
6万
查看次数

在调试时检查内存hsqldb

我们在内存中使用hdsqldb来运行针对数据库运行的junit测试.在通过弹簧配置运行每个测试之前设置db.一切正常.现在,当测试失败时,可以方便地检查内存数据库中的值.这可能吗?如果是这样的话?我们的网址是:

jdbc.url = JDBC:HSQLDB:MEM:TESTDB; sql.enforce_strict_size =真

每次测试后都会销毁数据库.但是当调试器运行时,数据库也应该仍然存在.我尝试连接sqldb databaseManager.这工作,但我没有看到任何表或数据.任何帮助都非常感谢!

java unit-testing hsqldb

39
推荐指数
3
解决办法
3万
查看次数

在Spring中将字符串数组注入bean

<?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需要一个字符串数组.

怎么在春天做?

java spring

16
推荐指数
1
解决办法
3万
查看次数

Console无法访问内存模式下的H2数据库

我在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)

h2 embedded-database

10
推荐指数
1
解决办法
2万
查看次数

Grails accessing H2 TCP server hangs

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 …

grails h2

8
推荐指数
2
解决办法
9374
查看次数

Connecting to H2 database from H2 Console

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)

spring h2 spring-boot

4
推荐指数
1
解决办法
1万
查看次数