运行JDBC嵌入式驱动程序java.sql.SQLSyntaxerrorexception时出错

运行JDBC嵌入式驱动程序java.sql.SQLSyntaxerrorexception时出错,java,jdbc,java-7,Java,Jdbc,Java 7,我的Java代码未编译: import java.sql.DriverManager; import java.sql.Statement; import java.sql.COnnection; import java.sql.SQLException; public class CreateTable { public static void main(String args[]) { final String DRIVER = "org.apache.derby.jdbc.Embedd

我的Java代码未编译:

import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.COnnection;
import java.sql.SQLException;
public class CreateTable {

public static void main(String args[]) {

final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
final String CONNECTION = "jdbc:derby:AccountDatabase;create=true";

try {
  Class.forName(DRIVER).newInstance();
 } catch (InstantiationException e) {
   e.printStackTrace();
 } catch (IllegalAccessException e) {
   e.printStackTrace();
 } catch (ClassNotFoundException e) {
   e.printStackTrace();
 }

 try (Connection connection = DriverManager.getConnection(CONNECTION);

      Statement statement = connection.createStatement()) {

     statement.executeUpdate(
      "create table ACCOUNTS                                            "
      + "  (NAME VARCHAR(32) NOT NULL PRIMARY KEY,                      "
      + "  ADDRESS VARCHAR(32),                                         "
      + "  BALANCE FLOAT)                                               ");

      statement.executeUpdate(
       "insert into ACCOUNTS values                                     "
       + "  ('Bill Gates', 'pluto', 1.000.000)");

       statement.executeUpdate(
       "insert into ACCOUNTS values                                     "
       + "  ('Steve Jobs', 'Mars', 1.000.000)");

      } catch (SQLException e) {
              e.printStackTrace();
        }
    }
}

我有java 7和jre版本7,两者都是兼容的。上面是CreateTable.java,它编译得很好。但是,当我第一次在嵌入式服务器上运行时,我就是这样运行它的(顺便说一句,它是CreateTable.class,没有类):

这是我在java中收到的错误:

java.sql.SQLSyntaxErrorException: Syntax error: Encountered ".000" at line 1, column 118.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.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.EmbedStatement.execute(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(Unknown Source)
    at CreateTable.main(CreateTable.java:33)
Caused by: java.sql.SQLException: Syntax error: Encountered ".000" at line 1, column 118.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransport
AcrossDRDA(Unknown Source)
    ... 9 more
 Caused by: ERROR 42X01: Syntax error: Encountered ".000" at line 1, column 118.
    at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
    at org.apache.derby.impl.sql.compile.ParserImpl.parseStatement(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)
    ... 3 more
数据库被创建了,我想我仍然能够检索数据,但显然不能。我必须编译完全没有错误,以检索此数据。是否有人可以帮助正确配置此文件,以便正确编译

如果您需要,我也可以发布GetData.java代码,但我认为没有必要。我99%确信,在使用GetData.java代码之前,我需要createTable.class正确运行。请帮忙?任何关于为什么会发生这种情况的想法

我还尝试重新编译,但出现如下错误:

java.sql.SQLException: Table/View 'ACCOUNTS' already exists in Schema 'APP'.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.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.EmbedStatement.executeStatement(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(Unknown Source)
    at CreateTable.main(CreateTable.java:27)
 Caused by: java.sql.SQLException: Table/View 'ACCOUNTS' already exists in Schema 'APP'.
     at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
     at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransport AcrossDRDA(Unknown Source)
     ... 10 more
 Caused by: ERROR X0Y32: Table/View 'ACCOUNTS' already exists in Schema 'APP'.
     at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
     at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.duplicateDescriptorException(Unknown Source)
    at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.addDescriptor(Unknown Source)
    at   org.apache.derby.impl.sql.execute.CreateTableConstantAction.executeConstantAction(Unknown Source)
    at org.apache.derby.impl.sql.execute.MiscResultSet.open(Unknown Source)
    at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
    at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
    ... 4 more

1.000.000
是您的问题<代码>是小数分隔符,而不是千位分隔符。

伙计,所有代码都在哪里?我们不是读心术的。嗨,欢迎来到stackoverflow。我们不需要如此详细的错误消息。无论如何,为了增加可读性,我对您的问题做了一些清理。@Leor a代码位于页面顶部。非常感谢Brett我是这个网站的新手,但随着我们的发展,我会变得更好。对于由此带来的不便,我深表歉意。(顺便说一句,不要使用FLOAT来存储余额。请使用DECIMAL).谢谢Maciej Stachowski-它已经完全编译好了,我很欣赏它的编码专业知识。我会给你+1票,但我必须提高我的声誉。我还将实现DECIMAL类型。
java.sql.SQLException: Table/View 'ACCOUNTS' already exists in Schema 'APP'.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.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.EmbedStatement.executeStatement(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(Unknown Source)
    at CreateTable.main(CreateTable.java:27)
 Caused by: java.sql.SQLException: Table/View 'ACCOUNTS' already exists in Schema 'APP'.
     at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
     at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransport AcrossDRDA(Unknown Source)
     ... 10 more
 Caused by: ERROR X0Y32: Table/View 'ACCOUNTS' already exists in Schema 'APP'.
     at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
     at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.duplicateDescriptorException(Unknown Source)
    at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.addDescriptor(Unknown Source)
    at   org.apache.derby.impl.sql.execute.CreateTableConstantAction.executeConstantAction(Unknown Source)
    at org.apache.derby.impl.sql.execute.MiscResultSet.open(Unknown Source)
    at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
    at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
    ... 4 more