Dodanie selectMovies()
This commit is contained in:
parent
8a208b6fe0
commit
645a9a9930
@ -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;
|
||||||
@ -84,7 +83,7 @@ public class Database {
|
|||||||
return books;
|
return books;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Album> selectAlbums() {
|
public List<Album> selectAlbums() {
|
||||||
List<Album> albums = new LinkedList<Album>();
|
List<Album> albums = new LinkedList<Album>();
|
||||||
try {
|
try {
|
||||||
ResultSet result = stat.executeQuery("SELECT * FROM albums");
|
ResultSet result = stat.executeQuery("SELECT * FROM albums");
|
||||||
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user