2013-08-01 3 views
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 1SQL 문은 Workbench에서 작동하지만 Java에서는 작동하지 않습니다.

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(); 

답변

2

:

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

변화 그것에

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

OMG 감사는'space' 치명적인 일이다. 내가 할 수있게되면 당신의 대답을 받아 들일 것입니다. – iridescent

+0

그런 SQL을 별도의 파일에 저장하는 것이 좋습니다. 더 나은 읽을 수있는 ... –

관련 문제