【发布时间】:2015-06-08 16:29:55
【问题描述】:
最近,我一直在尝试使用 NetBeans 8.0 连接到 derby 数据库。经过大量研究 SO (link1, link2, link3, link4 >) 和其他地方我无法理解如何让它消失。我意识到这是原因 :-(db.lck) 我没有连接到嵌入式 apache德比DB。
我注意到在我编译 Java 程序时出现了db.lck。 这是我被拒绝使用嵌入式 apache derby 连接的原因吗?
注意:-
1.我连接到 JavaDB 服务器。
2。编译程序时断开与数据库的连接。
3。添加了相关的jar文件derby.jar.
4.使用默认架构 APP 创建数据库,使用的用户名和密码都为 app。
5. 从连接字符串中删除了create=true 选项。
6. 我可以在 NetBeans 8.0 中通过 SQL 控制台查看和操作数据
提供以下代码以供进一步参考:
test.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class test
{
public static void main(String args [])
{
try {
Connection con = DriverManager.getConnection("jdbc:derby:C:/Users/Dhruvh/Documents/NetBeansProjects/ApacheDerby/derbytest","app","app");
PreparedStatement stmt=con.prepareStatement("select * from \"APP\".TABLE1");
ResultSet rs=stmt.executeQuery();
if(rs.next())
{
System.out.println("Id : "+rs.getInt(1) +" "+" name :"+rs.getString(2));
}
else
{
System.out.println("No word matching in database");
}
} catch (SQLException err) {
System.out.println(err.getMessage());
}
}
}
我也尝试过使用:-
PreparedStatement stmt=con.prepareStatement("select * from APP.TABLE1");PreparedStatement stmt=con.prepareStatement("select * from TABLE1");PreparedStatement stmt=con.prepareStatement("select * from app.table1"); //table was created in lower case
但我上面提到的所有内容都给出了相同的错误:-Table/View 'APP.TABLE1' does not exist.
堆栈跟踪:
java.sql.SQLSyntaxErrorException: Table/View 'APP.TABLE1' does not exist.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement42.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver42.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at test.main(test.java:12)
Caused by: ERROR 42X05: Table/View 'APP.TABLE1' does not exist.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.FromBaseTable.bindTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.compile.FromBaseTable.bindNonVTITables(Unknown Source)
at org.apache.derby.impl.sql.compile.FromList.bindTables(Unknown Source)
at org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
同时证明已创建 DB 的快照
请告知是否需要任何进一步的参考来解决问题。
感谢您的耐心等待
【问题讨论】:
-
有没有遇到过类似情况的人?
标签: java netbeans derby netbeans-8 javadb