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

时间:2013-01-19 20:39:09

标签: 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.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):

c:\programming\programs\Database Table>java -cp .;"\Program Files\Java\jdk1.7.0_06\db\lib\derby.jar" CreateTable

这是我在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 个答案:

答案 0 :(得分:1)

1.000.000是你的问题。 .是小数分数分隔符,而不是千位分隔符。