简体   繁体   English

如何在ClientDataSource中设置内存数据库?

[英]How to set up in-memory database in ClientDataSource?

First I was using this way how to get connection and all was fine. 首先,我使用这种方式来建立连接,一切都很好。

con = DriverManager.getConnection("jdbc:derby:memory:datab;create=true");

But now I have to change it to DataSource and how I find out derby had class ClientDataSource for this, but for the hell I can't find out how to setup that virtual DB in JUnit tests. 但是现在我必须将其更改为DataSource,以及如何查找derby的ClientDataSource类,但是对于地狱,我无法找到如何在JUnit测试中设置该虚拟DB的方法。

ClientDataSource ds = new ClientDataSource();
con = ds.getConnection();

Since I found this question during my googling : 由于我在谷歌搜索过程中发现了这个问题:

The answer is to use the EmbeddedDataSource instead of the ClientDataSource and to keep the "memory:" prefix before the database name 答案是使用EmbeddedDataSource而不是ClientDataSource并在数据库名称之前保留“ memory:”前缀

import org.apache.derby.jdbc.EmbeddedDataSource;
...
EmbeddedDataSource ds = new EmbeddedDataSource();

ds.setDatabaseName("memory:" + "datab");
ds.setCreateDatabase("create");
ds.setUser("user");
ds.setPassword("pwd");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM