gpt4 book ai didi

java - SQL 语句在 Workbench 中有效,但在 Java 中无效

转载 作者:行者123 更新时间:2023-11-29 08:25:44 24 4
gpt4 key购买 nike

下面的SQL语句在mySQL Workbench中有效,但是当我在Eclipse中执行它时,出现mySQL异常错误。 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行“by Schedule.id”附近使用的正确语法

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";

关于java - SQL 语句在 Workbench 中有效,但在 Java 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17992685/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com