带有子查询的准备好的语句给出语法错误
Prepared Statement with subquery Gives Syntax Errror
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
注意字符串连接之间所需的空格
...movie_ID)"+ "select ...
您有语法错误,因为您忘记了 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%'))");
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
注意字符串连接之间所需的空格
...movie_ID)"+ "select ...
您有语法错误,因为您忘记了 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%'))");