【发布时间】:2015-01-27 22:27:02
【问题描述】:
以下是我的示例代码的一部分:
public static void main(String[] args) throws Exception {
// TODO code application logic here
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
Connection c = DriverManager
.getConnection("jdbc:derby:DatabaseTrial;create=true");
System.out.println("connection ok");
String schema = "CREATE SCHEMA ABC";
String subj = "CREATE TABLE ABC.SUBJ (SUBJ_NO INT NOT NULL, DESCRIPTIVE_TITLE VARCHAR(80) NOT NULL, TEACHER VARCHAR(80), PRIMARY KEY (SUBJ_NO))";
String table = "CREATE TABLE ABC.REQ (REQ_NO INT NOT NULL, " +
"STATUS CHAR(8) DEFAULT NULL, SUBJ_NO INT NOT NULL, PRIMARY KEY (REQ_NO), FOREIGN KEY (SUBJ_NO) REFERENCES ABC.SUBJ(SUBJ_NO) ON DELETE CASCADE ON UPDATE CASCADE)";
String insert = "INSERT INTO ABC.REQ VALUES (1, DEFAULT, 1)";
String insert2 = "INSERT INTO ABC.SUBJ VALUES (1, 'Programming Application Lab', 'Mr. CBO Montes')";
Statement s = c.createStatement();
s.executeUpdate(schema);
s.executeUpdate(subj);
s.executeUpdate(table);
s.executeUpdate(insert2);
s.executeUpdate(insert);
ResultSet rs = s.executeQuery("SELECT * FROM ABC.MINE NATURAL JOIN ABC.SUBJ");
while (rs.next()) {
System.out.println(rs.getInt(1) + " " + rs.getString("STATUS") + " " + rs.getString("Subj_no") + " " + rs.getString("DESCRIPTIVE_TITLE") + " " + rs.getString("TEACHER"));
}
c.close();
}
而且我总是收到以下错误消息:
线程“main”java.sql.SQLSyntaxErrorException 中的异常:语法错误:在第 1 行第 196 列遇到“CASCADE”。 在 org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(未知来源) 在 org.apache.derby.impl.jdbc.Util.generateCsSQLException(未知来源) 在 org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(未知来源) 在 org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(未知来源) 在 org.apache.derby.impl.jdbc.EmbedConnection.handleException(未知来源) 在 org.apache.derby.impl.jdbc.ConnectionChild.handleException(未知来源) 在 org.apache.derby.impl.jdbc.EmbedStatement.execute(未知来源) 在 org.apache.derby.impl.jdbc.EmbedStatement.executeLargeUpdate(未知来源) 在 org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(未知来源) 在 TrialDBEmbedded.main(TrialDBEmbedded.java:26) 原因:错误 42X01:语法错误:在第 1 行第 196 列遇到“CASCADE”。 在 org.apache.derby.iapi.error.StandardException.newException(未知来源) 在 org.apache.derby.iapi.error.StandardException.newException(未知来源) 在 org.apache.derby.impl.sql.compile.ParserImpl.parseStatementOrSearchCondition(未知来源) 在 org.apache.derby.impl.sql.compile.ParserImpl.parseStatement(未知来源) 在 org.apache.derby.impl.sql.GenericStatement.prepMinion(未知来源) 在 org.apache.derby.impl.sql.GenericStatement.prepare(未知来源) 在 org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(未知来源) ... 4 更多
【问题讨论】:
标签: java jdbc derby embedded-database