简体   繁体   English

使用 Netbeans IDE / Derby 的 WHERE 子句上的 SQL 语法错误

[英]SQL syntax error on WHERE clause using Netbeans IDE / Derby

the following line is the cause of the error, but I fail to spot where specifically it is wrong.以下行是错误的原因,但我没有发现具体错误的地方。

PreparedStatement stmt = connection.prepareStatement("SELECT (SEATS - RESERVATIONS) AS AVAIL FROM RESERVATIONS "
                + " CROSS JOIN (SELECT COUNT(FACULTY) WHERE FACULTY = ? AND DATE = ?) "
                + " WHERE SEATS = ?");

Followed by the error,其次是错误,

java.sql.SQLSyntaxErrorException: Syntax error: Encountered "WHERE" at line 1, column 93.
at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.ClientConnection.prepareStatement(Unknown Source)
at ReservationEntry.reserveRoom(ReservationEntry.java:30)

Reservation Entry is the file that the prepared statement is in, any help would be appreciated.保留条目是准备好的语句所在的文件,任何帮助将不胜感激。

You need a FROM clause!你需要一个FROM子句! Some databases require them.一些数据库需要它们。 Something like this,perhaps:像这样的事情,也许:

SELECT (f.SEATS - r.RESERVATIONS) AS AVAIL
FROM RESERVATIONS R CROSS JOIN
     (SELECT COUNT(FACULTY) as SEATS
      FROM <table name goes here>
      WHERE FACULTY = ? AND DATE = ?
     ) F
WHERE SEATS = ?;

I doubt this does anything useful, though, other than fix the syntax errors.不过,除了修复语法错误之外,我怀疑这是否有任何用处。 You should ask a question with sample data, desired results, and an appropriate database tag.您应该提出一个带有示例数据、所需结果和适当的数据库标签的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM