我的 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% 确信我需要 createTable.class 才能正确运行,然后才能使用我的 GetData.java 代码。请帮忙?关于为什么会发生这种情况的任何想法。
我也尝试重新编译,但出现如下错误:
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