Dodanie selectMovies()

This commit is contained in:
Agnieszka Janicka 2016-06-05 00:54:54 +02:00
parent 8a208b6fe0
commit 645a9a9930

View File

@ -6,7 +6,6 @@
package library; package library;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
@ -105,6 +104,26 @@ public class Database {
return albums; return albums;
} }
public List<Movie> selectMovies() {
List<Movie> movies = new LinkedList<Movie>();
try {
ResultSet result = stat.executeQuery("SELECT * FROM movies");
int id, year;
String name, category, director;
while(result.next()) {
id = result.getInt("id");
year = result.getInt("year");
name = result.getString("name");
director = result.getString("director");
category = result.getString("category");
movies.add(new Movie(id, name, director, year, category));
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE);
}
return movies;
}
public void closeConnection() { public void closeConnection() {
try { try {