0

The SQL statement below works in mySQL Workbench, but when I execute it in Eclipse, there is an mySQL exeception error. 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();
asked Aug 1, 2013 at 11:22
0

1 Answer 1

2

that cannot work:

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

change it to

where schedule.movie_id=?"
 + " group by schedule.id";
answered Aug 1, 2013 at 11:29
Sign up to request clarification or add additional context in comments.

1 Comment

Omg thanks, the space is a deadly thing. Will accept your answer once I am able to.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.