package movie; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; public class Model { private String q; private String c; private ArrayList<TitleListResult> results; public void execute() { System.out.println("Hello"); try { Connection conn = ConnectUtilMy.connectDatabase(); // 住所の検索 String sql = "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 "; PreparedStatement pstmt; if (c.equals("全て")) { sql += " where title_name like ? or directed_name like ? or cast_name like ?"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, q + "%"); pstmt.setString(2, q + "%"); pstmt.setString(3, q + "%"); } else if (c.equals("タイトル名")) { sql += " where title_name like ?"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, q + "%"); } else if (c.equals("監督名")) { sql += " where directed_name like ?"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, q + "%"); } else if (c.equals("主演名")) { sql += " where cast_name like ?"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, q + "%"); } else { throw new RuntimeException("選択が不正です"); } pstmt.setMaxRows(50); ResultSet rs = pstmt.executeQuery(); // 検索結果の取得 results = new ArrayList<TitleListResult>(); while (rs.next()) { TitleListResult result = new TitleListResult(); result.Set_movie_name(rs.getString("title_name")); result.Set_years_publication(rs.getString("years_publication")); result.Set_performance_income(rs.getDouble("performance_income")); result.Set_Production_cost(rs.getDouble("production_cost")); result.Set_Public_evaluation(rs.getDouble("public_evaluation")); result.Set_Screening_time(rs.getString("screening_time")); result.Set_Genre_name(rs.getString("genre_number")); result.Set_original_name(rs.getString("original_name")); result.Set_cast_name(rs.getString("cast_name")); result.Set_directed_name(rs.getString("directed_name")); results.add(result); } // 切断 rs.close(); pstmt.close(); conn.close(); } catch (Exception ex) { ex.printStackTrace(); } } public ArrayList<TitleListResult> getResults() { return results; } public void setQ(String q) { this.q = q; } public void setC(String c) { this.c = c; } }
こちらのModel.javaファイルを実行するとトムキャットに
java.sql.SQLException: Column 'genre_number' not found. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) at com.mysql.cj.jdbc.result.ResultSetImpl.findColumn(ResultSetImpl.java:548) at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:852)
このようなエラーが出てしまいます。
過去にデータベースは同じ中身のままcmd上で動くmain.javaというものを作っていたのですが
そちらはなぜか動いています。
main.java
import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String args[]){ DataAccess data = new DataAccess(); Scanner scan = new Scanner(System.in); HashMap<Integer,TitleListResult>Title_hash=new HashMap<>(); System.out.print("キーワードを入力してください"); String a = scan.next(); Title_hash = data.result_search(a); System.out.println("キーワードに適合した結果を表示します\n"); for(int i=0;i<Title_hash.size();i++){ System.out.println("監督名"); System.out.println(Title_hash.get(i).Get_directed_name()); System.out.println("タイトル名"); System.out.println(Title_hash.get(i).Get_Title_name()); System.out.println("ジャンル"); System.out.println(Title_hash.get(i).Get_Genre_name()); System.out.println("原作"); System.out.println(Title_hash.get(i).Get_original_name()); System.out.println("主演"); System.out.println(Title_hash.get(i).Get_cast_name()); System.out.println("公開年"); System.out.println(Title_hash.get(i).Get_years_publication()); System.out.println("上映時間"); System.out.println(Title_hash.get(i).Get_Screening_time()); System.out.println("興行収入"); System.out.println(Title_hash.get(i).Get_performance_income()); System.out.println("制作費"); System.out.println(Title_hash.get(i).Get_Production_cost()); System.out.println("評価"); System.out.println(Title_hash.get(i).Get_Public_evaluation()); System.out.println('\n'); } } }
tableにおかしいところがあるのかそれともmodel.javaにおかしいところがあるのか分からないです。
中身のcreate tableです
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));
中身のinsertです
insert into genre_list(genre_name) values("SF"); insert into genre_list(genre_name) values("アクション"); insert into genre_list(genre_name) values("ロマンス"); insert into genre_list(genre_name) values("SF・アクション"); insert into directed_list(directed_name) values("ジェームズ・キャメロン"); insert into directed_list(directed_name) values("J・J・エイブラムス"); insert into directed_list(directed_name) values("ルッソ兄弟"); insert into directed_list(directed_name) values("コリン・トレボロウ"); insert into directed_list(directed_name) values("ジェームズ・ワン"); insert into directed_list(directed_name) values("ジョス・ウィードン"); insert into directed_list(directed_name) values("ライアン・クーグラ"); insert into directed_list(directed_name) values("ライアン・ジョンソン"); insert into original_list(original_name) values("なし"); insert into original_list(original_name) values("史実"); insert into original_list(original_name) values("アメリカンコミックス"); insert into prodction_list(prodction_name) values("アメリカ"); insert into prodction_list(prodction_name) values("イギリス"); insert into cast_list(cast_name) values("サム・ワーシントン"); insert into cast_list(cast_name) values("レオナルド・ディカプリオ"); insert into cast_list(cast_name) values("デイジー・リドリー"); insert into cast_list(cast_name) values("ロバートダウニーjr"); insert into cast_list(cast_name) values("クリス・プラット"); insert into cast_list(cast_name) values("ヴィン・ディーゼル"); insert into cast_list(cast_name) values("チャドウィック・ボーズマン"); insert into movie( movie_number, title_name, years_publication, performance_income, production_cost, public_evaluation, screening_time, genre_number, directed_number, original_number, cast_number) values(1,"アバター","2009",278230,23700000000,3,"2時間42分",1,1,1,1); (ここからこの下には上のinto movieとほぼ同じで内容だけ違う項目が9つ続きます。)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/22 05:55