使用derby在netbeans中查询嵌入式数据库 [英] querying embedded database in netbeans using derby

查看:326
本文介绍了使用derby在netbeans中查询嵌入式数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用netbeans创建了一个嵌入式数据库并向其添加了数据。所以现在我想查询数据库,代码运行流畅但不显示数据。这是我的代码:

I have created an embedded database using netbeans and added data to it. so now i want to query the database, the code runs smoothly but doesn't display data. Here is my code:

import java.sql.*;
public class EmbeddedDB 
{  

public static void main(String[] args)
{
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;
    try
    {
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        con = DriverManager.getConnection("jdbc:derby:CustDB;create=true", "app", "app");
        System.out.println("connected");
        st = con.createStatement();
        System.out.println("statement created");

        rs = st.executeQuery("select * from APP.TABLEX");
        System.out.println("retrieving ...");
        System.out.println(rs.getString(1));

    }
    catch(ClassNotFoundException | SQLException c)
    {
    }
}
}

那么可能是什么问题?数据库是以嵌入模式创建的。

so what could be the problem? the database was created in an embedded mode.

推荐答案

您告诉我们我创建了一个嵌入式数据库。 ..并向其添加数据。

因此,此数据库必须在Netbeans Services中可见。

Thus, this database must be visible in Netbeans Services.

NO ; create = true

您应该使用在属性中看到的相同URL进行连接。还有更多。

展开数据库URL或查看底部。

NO ;create=true !
You should connect with the same URL you see in the properties. Nothing more.
Expand Database URL or look at the bottom.

 con = DriverManager.getConnection("jdbc:derby:C:/Dokumente und Einstellungen/Administrator/.netbeans-derby/sample","app","app");

在嵌入式模式下,Derby在应用程序的JVM(Java虚拟机)中运行。在此模式下,只有应用程序可以访问数据库,例如另一个用户/应用程序将无法访问该数据库。

In the embedded mode Derby runs within the JVM (Java Virtual Machine) of the application. In this mode only the application can access the database, e.g. another user / application will not be able to access the database.

只有一个应用程序可以访问数据库。

请断开Netbeans Services,即要在应用程序中连接的数据库。

Only one Application can acces the Database.
So disconnect in Netbeans Services, the Database you want to connect to in your Application.

这篇关于使用derby在netbeans中查询嵌入式数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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