Dodanie selectBooks()

This commit is contained in:
Agnieszka Janicka 2016-06-05 00:46:30 +02:00
parent 141fe04411
commit 4280ed4032
3 changed files with 21 additions and 34 deletions

Binary file not shown.

View File

@ -13,13 +13,13 @@ public class Book extends Item{
Book(){
//nothing to do
}
Book(int id, String n, String an, String asn, int y, String isbn, String p){
Book(int id, String n, String an, String asn, int y, String isbn, String p, String c){
this.setId(id);
this.setName(n);
this.authorName = an;
this.authorSurname = asn;
this.setYear(y);
this.setCategory("NULL");
this.setCategory(c);
this.ISBN = isbn;
this.publishing = p;
}

View File

@ -20,7 +20,7 @@ import javax.swing.JOptionPane;
public class Database {
public static final String DRIVER = "org.sqlite.JDBC";
public static final String DB_URL = "jdbc:sqlite:biblioteka.db";
public static final String DB_URL = "jdbc:sqlite:biblioteka.db"; // ścieżka do bazy
private Connection conn;
private Statement stat;
@ -53,59 +53,46 @@ public class Database {
stat.execute(createAlbums);
stat.execute(createMovies);
} catch (SQLException e) {
System.err.println("Blad przy tworzeniu tabeli");
JOptionPane.showMessageDialog(null, "Błąd przy tworzeniu tabel bazy danych.", "Error:", JOptionPane.INFORMATION_MESSAGE);
return false;
}
return true;
}
public List<Book> selectCzytelnicy() {
public List<Book> selectBooks() {
List<Book> books = new LinkedList<Book>();
try {
ResultSet result = stat.executeQuery("SELECT * FROM books");
int id;
String imie, nazwisko, pesel;
int id, year;
String name, authorName, authorSurname, isbn, category, publishing;
while(result.next()) {
id = result.getInt("id_czytelnika");
imie = result.getString("imie");
nazwisko = result.getString("nazwisko");
pesel = result.getString("pesel");
books.add(new books(id, imie, nazwisko, pesel));
id = result.getInt("id");
year = result.getInt("year");
name = result.getString("name");
authorName = result.getString("author_name");
authorSurname = result.getString("author_surname");
publishing = result.getString("publishing");
isbn = result.getString("isbn");
category = result.getString("category");
books.add(new Book(id, name, authorName, authorSurname, year, isbn, publishing, category));
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE);
}
return czytelnicy;
}
public List<Ksiazka> selectKsiazki() {
List<Ksiazka> ksiazki = new LinkedList<Ksiazka>();
try {
ResultSet result = stat.executeQuery("SELECT * FROM ksiazki");
int id;
String tytul, autor;
while(result.next()) {
id = result.getInt("id_ksiazki");
tytul = result.getString("tytul");
autor = result.getString("autor");
ksiazki.add(new Ksiazka(id, tytul, autor));
}
} catch (SQLException e) {
e.printStackTrace();
return null;
}
return ksiazki;
return books;
}
public void closeConnection() {
try {
conn.close();
} catch (SQLException e) {
System.err.println("Problem z zamknieciem polaczenia");
JOptionPane.showMessageDialog(null, "Problem z zamknięciem połączenia.", "Error:", JOptionPane.INFORMATION_MESSAGE);
e.printStackTrace();
}
}
}
}