【问题标题】:db.lck appears while compiling a java program using a derby database使用 derby 数据库编译 java 程序时出现 db.lck
【发布时间】: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


【解决方案1】:

您提供了一个不存在的数据库的 derby 位置,因此它会尝试自己创建数据库。

jdbc:derby:C:/Users/Dhruvh/Documents/NetBeansProjects/ApacheDerby/src/derbytest;**create=true**

粗体部分是您在创建驱动程序时忽略的默认参数。

您可以连接到数据库,但不存在您要访问的表。您必须修复数据库的位置。此外,如果您通过程序连接到数据库(看起来像 mplab x ?),您需要先终止该连接。

【讨论】:

  • 不,我错误地发布了那个位置。原始位置是Connection con = DriverManager.getConnection("jdbc:derby:C:/Users/Dhruvh/Documents/NetBeansProjects/ApacheDerby/derbytest;create=true","app","app"); 在问题中更正,我现在再次检查它,一旦数据库文件夹仍然存在
  • 错误仍然存​​在,我没有使用任何类似 mplab x 的应用程序
  • 您仍在连接到两个不同的数据库。在访问表之前运行它。 CREATE TABLE APP.TABLE1 (ID int PRIMARY KEY NOT NULL); ALTER TABLE APP.TABLE1 添加列名 VARCHAR (30);
  • CREATE TABLE APP.TABLE1 (ID int PRIMARY KEY NOT NULL); 给了Error code 30000, SQL state X0Y32: Table/View 'TABLE1' already exists in Schema 'APP'.
  • ` ALTER TABLE APP.TABLE1 ADD COLUMN NAME VARCHAR (30);`给Error code 30000, SQL state X0Y32: Column 'NAME' already exists in Table/View '"APP"."TABLE1"'.
猜你喜欢
  • 2012-11-26
  • 1970-01-01
  • 1970-01-01
  • 2014-08-20
  • 1970-01-01
  • 2015-03-03
  • 1970-01-01
  • 2013-10-01
  • 1970-01-01
相关资源
最近更新 更多