带有子查询的java预处理语句给出语法错误

5kgi1eie  于 2021-06-15  发布在  Mysql
关注(0)|答案(2)|浏览(319)

**结案。**此问题不可复制或由打字错误引起。它目前不接受答案。
**想改进这个问题吗?**更新问题,使其成为堆栈溢出的主题。

两年前关门了。
改进这个问题

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
agxfikkp

agxfikkp1#

你有语法错误,因为你忘了 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%'))");
ccrfmcuu

ccrfmcuu2#

注意字符串连接之间所需的空格

...movie_ID)"+ "select ...

相关问题