SQL语句可在Workbench中工作,但不能在Java中工作 [英] SQL statement works in Workbench but not in Java

查看:195
本文介绍了SQL语句可在Workbench中工作,但不能在Java中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的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

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

推荐答案

无效:

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

将其更改为

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

这篇关于SQL语句可在Workbench中工作,但不能在Java中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆