当使用jdbc:embedded-database时,如何连接到Spring创建的HSQL? [英] How to connect to HSQL which Spring creates when jdbc:embedded-database is used?

查看:423
本文介绍了当使用jdbc:embedded-database时,如何连接到Spring创建的HSQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring自动为我创建的HSQL数据库:

I have a HSQL database which Spring automatically creates for me:

<jdbc:embedded-database id="dataSource" type="HSQL">
    <jdbc:script location="classpath:scheme.sql" /
</jdbc:embedded-database>

现在我想连接到该数据库.我的问题是如何执行此操作,因为我不知道应该使用哪个地址.

And now I want to connect to this database. My question is how to do this, because I don't known which address I should use.

推荐答案

此嵌入式HSQL数据库是全内存的和进程内的,因此只能从Spring Java进程访问.如果还希望通过其他工具访问数据库,例如使用数据库管理器检查内容,则可以使用内存中实例启动HSQLDB服务器,然后从Spring和其他工具连接到该服务器.

This embedded HSQL database is all-in-memory and in-process, therefore accessible only from the Spring Java process. If you want to access the database from another tool as well, for example to check the contents with a database manager, you can start an HSQLDB server with an all-in-memory instance, then connect to the server from Spring and other tools.

HSQLDB指南 http://hsqldb.org/doc中对此进行了介绍/2.0/guide/listeners-chapt.html

使用以下命令启动服务器:

The server is started with this command:

java -cp ../lib/hsqldb.jar org.hsqldb.Server --database.0 mem:test --dbname.0 test

您需要使用用户名"SA"和密码"创建一个Spring数据源.用于配置Spring数据源的数据库驱动程序和URL(来自同一台机器)是:

You need to create a Spring data source with username "SA" and password "". The database driver and URL (from the same machine) to configure the Spring data source are:

org.hsqldb.jdbcDriver
jdbc:hsqldb:hsql://localhost/test

这篇关于当使用jdbc:embedded-database时,如何连接到Spring创建的HSQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆