こちらの画像のように検索する際にタイトル名,監督名,主演名の中のどれかひとつを決めて検索できる仕様にしたいです。
いまの形だとその中のどれでもよい場合という形になってしまっているのでどこをどう治し付け足せば
画像のような条件を一つに絞って検索できるようになるのでしょうか。
テーブルのクリエイト文です
create table movie( movie_number int, title_name varchar(400) not null, years_publication char(4) not null, performance_income varchar(50) not null, production_cost varchar(50) not null, public_evaluation double not null, screening_time varchar(10) not null, genre_number int not null, directed_number int not null, original_number varchar(400) not null, cast_number int not null, constraint MV primary key(movie_number), constraint FK_1 foreign key(genre_number) references genre_list(genre_number), constraint FK_2 foreign key(directed_number) references directed_list(directed_number), constraint FK_3 foreign key(original_number) references original_list(original_number), constraint FK_4 foreign key(cast_number) references cast_list(cast_number)); create table genre_list( genre_name varchar(400) not null , genre_number int auto_increment , constraint GN primary key(genre_number)); create table directed_list( directed_name varchar(400) not null , directed_number int auto_increment , constraint DI primary key(directed_number)); create table original_list( original_name varchar(400) not null , original_number int auto_increment , constraint OI primary key(original_number)); create table prodction_list( prodction_name varchar(400) not null , prodction_number int auto_increment, constraint PR primary key(prodction_number)); create table cast_list( cast_name varchar(400) not null , cast_number int auto_increment, constraint MA primary key(cast_number));
こちらがその検索する際の中身です。"SELECT 文の中身を変えればいいのだと思うのですがどう変えればいいかわかりません。
package movie; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.HashMap; public class Model { private String q; private String c; private Connection conn = null; private PreparedStatement stmt = null; private ResultSet resultSet = null; private HashMap<Integer, TitleListResult> Title_hash; HashMap<Integer, String[]> results = new HashMap<Integer, String[]>(); public void execute() { System.out.println("Hello"); try { conn = ConnectUtilMy.connectDatabase(); // 住所の検索 PreparedStatement pstmt = conn.prepareStatement( ** "SELECT title_name,years_publication,performance_income,production_cost,public_evaluation,screening_time,genre_name,original_name,cast_name,directed_name " + "FROM movie inner join original_list on movie.original_number=original_list.original_number " + "inner join genre_list on movie.genre_number=genre_list.genre_number " + "inner join directed_list on movie.directed_number=directed_list.directed_number " + "inner join cast_list on movie.cast_number=cast_list.cast_number where title_name like ? or directed_name like ?");** pstmt.setString(1, q + "%"); pstmt.setMaxRows(50); ResultSet rs = pstmt.executeQuery(); // 検索結果の取得 int i = 0; while (rs.next()) { String[] result = new String[10]; result[0] = rs.getString("movie_number"); result[1] = rs.getString("years_publication"); result[2] = rs.getString("performance_income"); result[3] = rs.getString("production_cost"); result[4] = rs.getString("public_evaluation"); result[5] = rs.getString("screening_time"); result[6] = rs.getString("genre_number"); result[7] = rs.getString("directed_number"); result[8] = rs.getString("original_number"); result[9] = rs.getString("cast_number"); results.put(i++, result); } // 切断 rs.close(); pstmt.close(); conn.close(); } catch (Exception ex) { ex.printStackTrace(); } } public HashMap<Integer, String[]> getResults() { return results; } public void setQ(String q) { this.q = q; } public void setC(String c) { this.c = c; } }
回答1件
あなたの回答
tips
プレビュー