您好我有一個代碼,查詢信息從數據庫中,一旦它獲取信息的值存儲在價值bean(許多行信息可以從MySQL中檢索)。我應該創造一些東西一樣存儲信息價值bean
movie movies[i] = new movie();
movies[i].setMovieID(rs.getInt("Movie_ID"));
movies[i].setMovieTitle(rs.getString("Movie_Title"));
movies[i].setReleaseDate(rs.getDate("Release_Date"));
movies[i].setImage(rs.getString("Image"));
movies[i].setDescription(rs.getString("Description"));
movies.add(movies[i]);
-instead OF-
public class MovieDB {
public ArrayList movies (String query){
ArrayList movies= new ArrayList();
try {
// step 1 : load JDBC Driver
Class.forName("com.mysql.jdbc.Driver");
//step2 : define Connection URL
String connURL = "jdbc:mysql://localhost:3306/sp_movie?user=root&password=deepak1990";
//step3 establish connection url
Connection conn = DriverManager.getConnection(connURL);
String sql="{call "+query+"}";
CallableStatement cs=conn.prepareCall(sql);
ResultSet rs=cs.executeQuery();
// 1) This part
while(rs.next()){
movie movies1 = new movie();
movies1.setMovieID(rs.getInt("Movie_ID"));
movies1.setMovieTitle(rs.getString("Movie_Title"));
movies1.setReleaseDate(rs.getDate("Release_Date"));
movies1.setImage(rs.getString("Image"));
movies1.setDescription(rs.getString("Description"));
movies.add(movies1);
}
} catch (Exception e){
} finally {
try {
} catch (Exception e) {}
}
return movies;
}
}
你的第一選擇不會編譯'電影電影[i] =新電影();' – fmodos