I have created a system that creates a database with sql and searches it on html using java.
I am trying to create a database that contains multiple information such as movie titles and release years, and try to search on html, but it does not work.
I am instructed by e-mail what to do next, but it's difficult and I don't understand.
I want to get the results of a database search in a file called Model.java.
In order to do so, it seems that the process of getting the search result should be rewritten to hold it in ArrayList.
I'm not sure what to hold in an ArrayList
It is said that it is already done in the previously created file called DataAcces.java. What part of DataAcces.java is
Form that retains the process of obtaining the search result in ArrayList
I don't know, so I would appreciate it if you could tell me.
package movie;
import java.sql.*;
import java.util.HashMap;
public class DataAccess
{
private Connection conn = null;
private PreparedStatement stmt = null;
private ResultSet resultSet = null;
private HashMap
private String sql = null;
public HashMap
Title_hash = new HashMap<>();
int i = 0;
try {
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 where title_name like? or directed_name like ?";
conn = ConnectUtilMy.connectDatabase();
stmt = conn.prepareStatement(sql);
stmt.setString(1,"%"+search+"%");
stmt.setString(2,"%"+search+"%");
System.out.println(search);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
TitleListResult result = new TitleListResult();
result.Set_Title_name( resultSet.getString("title_name"));
result.Set_years_publication( resultSet.getString("years_publication"));
result.Set_performance_income( resultSet.getDouble("performance_income"));
result.Set_Production_cost( resultSet.getDouble("production_cost"));
result.Set_performance_income( resultSet.getDouble("performance_income"));
result.Set_Public_evaluation( resultSet.getDouble("public_evaluation"));
result.Set_Screening_time( resultSet.getString("screening_time"));
result.Set_Genre_name( resultSet.getString("genre_name"));
result.Set_directed_name( resultSet.getString("directed_name"));
result.Set_cast_name( resultSet.getString("cast_name"));
result.Set_original_name( resultSet.getString("original_name"));
Title_hash.put(i,result);
i++;
}
}
catch (SQLException ex) {
System.out.println("Error code:" + ex.getErrorCode());
System.out.println("SQL state:" + ex.getSQLState());
ex.printStackTrace();
}
finally {
try {
if (resultSet != null) {
resultSet.close();
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
try {
if (stmt != null) {
stmt.close();
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
try {
if (conn != null) {
conn.close();
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
return Title_hash;
}
}
-
Answer # 1
Related articles
- java - questions about the output result of the simple program
- java - processing to add and return the characters entered in the array
- java - [jsp/servlet/sql] the result display from db cannot be displayed well
- c# - if you do not add a delay to the processing, the execution result will be strange
- mysql - call model in viewhelper and pass the search result to view
- java - cannot search by entering "%" or "_" in the search box
- java - i want to perform fuzzy search using bind variables
- java - search multiple items about how to write findby 〇 and △ like()
- java - i want to store the information obtained from dto in the dto type of arraylist
- java - depending on the sort of recyclerview, the elements of arraylist can be overwritten only for the first time
- java - about fuzzy search function of spring boot
- java - processing to store the value of the text file in a variable
- java - i want to perform search evaluation of board games without using recursive expressions
- java - program code after processing periodic task of timer class does not work
- java - language characteristics "processing speed" "safety" "coding speed"
- java - a description of processing according to input conditions from the command line
- java - about generics of binary search
- java - [processing] want to instantiate every second
- java - functional interface and calculation processing
- javascript : How to refresh a page after deletion using checkboxes
- Grouping in SQL query in Spring Data Java project insistently requires id
- How to pull data from a database (MySQL) using PHP?
- How to extract data from MySQL using php in java?
- java : Exception when dropping table if it doesn't exist
- How to use th:each to pass a string to JavaScript code embedded in an html page
- java : ArrayList elements added from Json are mixed up
- php : How to implement sending data to the database from the forms displayed by the cycle?
- how to get the value of an element stored in shadow-root? java + Selenide
- Java SQL function call in Criteria
I suppose this is because it will be rewritten,
if possible,
"Currently, I'm putting the fetched results from the DB in a HashMap. Is this meant to be an ArrayList instead of a HashMap?"
I should ask the person giving the instruction.