简体   繁体   中英

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! 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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