gpt4 book ai didi

java - 带子查询的准备语句给出语法错误

转载 作者:行者123 更新时间:2023-11-29 16:35:32 25 4
gpt4 key购买 nike

PreparedStatement amovie = con.prepareStatement("INSERT INTO actor_movie(actor_ID, movie_ID)"+ "select actor_ID from actor" + "where actor.surname = 'Depp', select movie_ID from movie where movie.title LIKE 'Caribbean%'");

有人可以告诉我这个查询有什么问题吗?我查遍了互联网,但找不到解决方案。

错误消息:

Exception in thread "main" 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 ', select movie_ID from movie where title LIKE 'Caribbean%'' at line 1

最佳答案

您有语法错误,因为您忘记了 VALUES 并将 SELECT 语句括在括号中。
更改为:

PreparedStatement amovie = con.prepareStatement(
"INSERT INTO actor_movie(actor_ID, movie_ID) VALUES ((select actor_ID from actor where actor.surname = 'Depp'), (select movie_ID from movie where movie.title LIKE 'Caribbean%'))");

关于java - 带子查询的准备语句给出语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53618323/

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