0

下面的 SQL 语句在 mySQL Workbench 中工作,但是当我在 Eclipse 中执行它时,会出现 mySQL 异常错误。 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by schedule.id' at line 1

String sqlStr = "select movie_db.movie , schedule.date , schedule.timeslot "
                        + ", schedule.seats as NoSeats,"
                        + " a.bookingsMade, if ( (schedule.seats-a.bookingsMade) is null, schedule.seats,(schedule.seats-a.bookingsMade) ) as availSeats"
                        + " ,schedule.movie_id, schedule.id as scID"
                        + " from schedule"
                        + " left outer join movie_db on ( movie_db.id=schedule.movie_id )"
                        + " left outer join ("
                        + " select count(*) as bookingsMade, tickets.movie_id as aid from tickets"
                        + " group by schedule_id"
                        + " ) as a on (schedule.id=a.aid)"
                        + " where schedule.movie_id=?"
                        + "group by schedule.id";

PreparedStatement pstmt = sqlConnect.getPreparedStatement(sqlStr);
pstmt.setInt(1, Integer.parseInt(movieId));

ResultSet rs = pstmt.executeQuery();
4

1 回答 1

2

那行不通:

where schedule.movie_id=?"
                        + "group by schedule.id";

将其更改为

where schedule.movie_id=?"
                    + " group by schedule.id";
于 2013-08-01T11:29:33.917 回答