在IntelliJ Idea 13中创建/配置Derby JDBC Client [英] Creating/Configuring Derby JDBC Client in IntelliJ Idea 13

查看:708
本文介绍了在IntelliJ Idea 13中创建/配置Derby JDBC Client的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对此(也许)愚蠢的问题感到抱歉。
我需要在我的java项目中创建一些本地数据库,所以我决定使用Apache Derby Client。我正在使用 IntelliJ IDEA 13 Ultimate ,我的问题是我不知道,如何创建本地数据库。
Jetbrains网站上的教程没用,因为有些文章只关于连接到远程数据库,而不是本地(或者至少我还没有找到它们)。

Sorry for this (maybe) stupid question. I need to create some local DB in my java project so I've decided for Apache Derby Client. I am working with IntelliJ IDEA 13 Ultimate and my problem is that I don't know, how to create local database. Tutorials at Jetbrains websites aren't useful because there are articles only about connecting to the remote DB, not to the local one (or at least I didn't find them yet).

到目前为止我做了什么:

What have I done so far:


  1. 我试图通过创建新的远程德比来设置数据库数据源。
    有关设置的屏幕截图:数据库设置屏幕

  1. I've tried to set the DB up by creating new remote derby data source. Screenshot with the settings: DB Settings screen

用户名和密码相同: admin


  1. 点击测试连接后,抛出此错误:错误

  2. 当我点击时应用确定,它表示它已连接,但异常仍在那里。

  1. After clicking test connection, this error is thrown: error
  2. When I click apply and ok, it says that it's connected, but exception is still there.

那么你知道问题出在哪里吗?
我有一个名为 DatabaseSetting.java的小型配置类

So do you have any idea where the problem can be? I've got small confiuration class called DatabaseSetting.java

package issuetrackinglite;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseSetting {

private String dbURL = "jdbc:derby://localhost:1527/MallDB;create=true";
private String user = "admin";
private String password = "admin";
private Connection connection;



public static final String CREATE_ITEMS_DB = "CREATE TABLE items (item_id INTEGER NOT NULL, item_name VARCHAR(20) NOT NULL, item_price REAL NOT NULL, multiplicity_shop INTEGER NOT NULL, multiplicity_store INTEGER NOT NULL)";
public static final String INSERT_PRODUCT = "INSERT INTO items (item_id, item_name, item_price, multiplicity_shop, multiplicity_store) VALUES (?, ?, ?, ?, ?)";
public static final String CLEAR_ITEMS_DB = "DELETE FROM items";

// -------------------------------------------------------------

protected Connection connectToDB() {

    try {

        connection = DriverManager.getConnection(dbURL, user, password);

        return connection;

    } catch (SQLException ex) {
        System.out.println("SQL exception - connectToDB(): " + ex.getMessage());
        return null;
    }

}

}

编辑

简单解释:我只需要创建虚拟德比数据库,每次都会创建程序开始。
我不知道,怎么在IntelliJ中做到这一点。
我已将 DERBY_HOME 添加到环境变量中,并添加了Derby的路径。现在IntelliJ抛出此错误:错误窗口

Simply explained: I just need to create virtual derby database which will be created every time at the program start. I don't know, how to do it in IntelliJ. I've added DERBY_HOME to the enviroment variables and also added path to Derby. Now this error is thrown by IntelliJ: Error window

非常感谢你的帮助和时间

Thank you very much for your help and time

推荐答案

我成功地完成了这项工作。以下是我成功配置本地Derby数据库以在IntelliJ Idea 13/14中工作的步骤。

I've managed to get this work. Here are the steps that I've made to successfully configure local Derby database to work in IntelliJ Idea 13/14.


  1. 首先,您需要在IDEA中使用它之前手动启动derby服务器(如果它尚未运行)。我通常通过键入以下命令提示符来执行此操作:

  1. First, you need to manually start derby server (if it is not already running) before using it in IDEA. I usually do it via command prompt by typing:


C:\ Users \PcName> startNetworkServer -noSecurityManager

C:\Users\PcName>startNetworkServer -noSecurityManager

此命令将在端口号上启动derby服务器: 1527 。确保在环境变量中正确设置路径

This command will start derby server on port number: 1527. Make sure you have correctly set path in enviroment variables

接下来转到IDEA,打开数据库窗口,单击绿色加号在左上角和下拉菜单中选择:数据源 - >德比 - >远程

Next go to IDEA, open Database window, click on the green plus sign in the upper left corner and in the dropdown menu choose: Data Source -> Derby -> Remote

您可以使用我的问题中屏幕截图中提供的设置激发灵感。您还可以下载Derby驱动程序文件。 IDEA只需单击下载按钮即可完成。

You can inspire with my settings provided in the screenshot in my question. You can also download Derby driver files. IDEA does it just by clicking on the download button.

我总是使用的基本模板是这样的:

Basic template which I always use is something like that:

名称字段应采用以下格式: Derby - YourDatabaseName; create = true @ localhost

主机字段应该 localhost 里面

端口必须 1527

数据库字段必须是以下形式: YourDatabaseName; create = true

要连接的Urc: jdbc:derby:// localhost:1527 / YourDatabaseName; create = true

(可选) - 您可以指定数据库用户名和密码。在IDEA 14中,有一个复选框保存在磁盘上并带有主密码保护,我个人总是不加以控制。

(Optional) - You can specify your database user name and password. In IDEA 14 there is a checkbox Save on disk with master password protection, which I personally always leave unchecked.

就是这样。我希望这个小指南能帮助某人在Intellij IDEA中配置Derby

That's it. I hope this little guide will help somebody to configure Derby in Intellij IDEA

这篇关于在IntelliJ Idea 13中创建/配置Derby JDBC Client的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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