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 コードを投稿することもできますが、必要ではないと思います。GetData.java コードを使用する前に、createTable.class を正しく実行する必要があることは 99% 確信しています。助けてください?なぜこれが発生するのかについてのアイデア。
また、再コンパイルしようとしましたが、次のようなエラーが発生します。
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