有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

从多个表中选择mysql Java

如何使用给定的剧院城市变量向Arraylist插入不同的电影标题

例如,我希望在Arraylist中填充showtimes表中链接到其城市为洛杉矶的剧院id的所有电影标题

showtimes表格

id  movieId theaterId 
1   1        1
2   1        1
3   1        2
4   1        2
5   2        2
6   2        2
7   1        3
8   4        1

剧院

id city
1  LA
2  NY
2  NJ

电影表格

id  title 
1   avengers  
2   matrix   
3   lotr
4   inception

结果Arraylist应填充为:复仇者和盗梦空间 因为laid是1,它在showtimes表中导致movieId1,1,4 这些{}导致电影表标题为《复仇者》和《盗梦空间》(复仇者只能插入一次(不同))


共 (1) 个答案

  1. # 1 楼答案

    您可以通过JDBC在数据库中执行此操作,例如

    SELECT
            DISTINCT movies.title
        FROM
            showtimes
            ,theaters
            ,movies
        WHERE
            movies.id = showtimes.movieID
            AND showtimes.theatreID = theatre.id
            AND theatre.city = 'LA';
    

    然后迭代结果集并将其添加到ArrayList