【发布时间】:2013-05-21 11:43:13
【问题描述】:
我已经使用 netbeans 创建了一个嵌入式数据库并向其中添加了数据。所以现在我想查询数据库,代码运行流畅但不显示数据。这是我的代码:
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)
{
}
}
}
那么可能是什么问题?数据库是以嵌入式模式创建的。
【问题讨论】:
-
您确定向其中添加数据的 CustDB 数据库与此 main 方法运行时类路径中的数据库相同吗?
-
@Tap,是的。在编写查询它的代码之前,我已经创建了一个 CustDB。
-
不过,我还是会在文件系统中搜索 CustDB。如果它出现两次,那么您的程序创建了一个新的空数据库。
-
“您确定向其中添加数据的 CustDB 数据库与此 main 方法运行时类路径中的数据库相同吗?– 点击 4 小时前”。您能否详细说明您的问题?
-
CustDB 的文件系统?