diff --git a/build/classes/library/Album.class b/build/classes/library/Album.class index bfce847..7228219 100644 Binary files a/build/classes/library/Album.class and b/build/classes/library/Album.class differ diff --git a/build/classes/library/AlbumFieldPattern.class b/build/classes/library/AlbumFieldPattern.class index 54b566d..c0708a2 100644 Binary files a/build/classes/library/AlbumFieldPattern.class and b/build/classes/library/AlbumFieldPattern.class differ diff --git a/build/classes/library/Book.class b/build/classes/library/Book.class index d00828c..5348abd 100644 Binary files a/build/classes/library/Book.class and b/build/classes/library/Book.class differ diff --git a/build/classes/library/BookFieldPattern.class b/build/classes/library/BookFieldPattern.class index 9e1990f..b831827 100644 Binary files a/build/classes/library/BookFieldPattern.class and b/build/classes/library/BookFieldPattern.class differ diff --git a/build/classes/library/Item.class b/build/classes/library/Item.class index f2abe1a..8d1d869 100644 Binary files a/build/classes/library/Item.class and b/build/classes/library/Item.class differ diff --git a/build/classes/library/Movie.class b/build/classes/library/Movie.class index a8bc7f1..44627d7 100644 Binary files a/build/classes/library/Movie.class and b/build/classes/library/Movie.class differ diff --git a/build/classes/library/MovieFieldPattern$1.class b/build/classes/library/MovieFieldPattern$1.class index 8258a23..a6e2d7b 100644 Binary files a/build/classes/library/MovieFieldPattern$1.class and b/build/classes/library/MovieFieldPattern$1.class differ diff --git a/build/classes/library/MovieFieldPattern$2.class b/build/classes/library/MovieFieldPattern$2.class index 050a8e1..a030694 100644 Binary files a/build/classes/library/MovieFieldPattern$2.class and b/build/classes/library/MovieFieldPattern$2.class differ diff --git a/build/classes/library/MovieFieldPattern$3.class b/build/classes/library/MovieFieldPattern$3.class index 77a465f..f258b3e 100644 Binary files a/build/classes/library/MovieFieldPattern$3.class and b/build/classes/library/MovieFieldPattern$3.class differ diff --git a/build/classes/library/MovieFieldPattern$4.class b/build/classes/library/MovieFieldPattern$4.class index 225a062..03f7714 100644 Binary files a/build/classes/library/MovieFieldPattern$4.class and b/build/classes/library/MovieFieldPattern$4.class differ diff --git a/build/classes/library/MovieFieldPattern.class b/build/classes/library/MovieFieldPattern.class index f4d794c..696b63e 100644 Binary files a/build/classes/library/MovieFieldPattern.class and b/build/classes/library/MovieFieldPattern.class differ diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 8c75c96..67a401a 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -8,6 +8,7 @@ file:/D:/PROJEKT/Library/src/library/MainMenu.java file:/D:/PROJEKT/Library/src/library/Item.java file:/D:/PROJEKT/Library/src/library/Validation.java + file:/D:/PROJEKT/Library/src/library/Album.java file:/D:/PROJEKT/Library/src/library/AlbumFieldPattern.java file:/D:/PROJEKT/Library/src/library/Book.java file:/D:/PROJEKT/Library/src/library/Database.java diff --git a/src/library/Album.java b/src/library/Album.java index dab8af8..ef4056a 100644 --- a/src/library/Album.java +++ b/src/library/Album.java @@ -5,6 +5,8 @@ */ package library; +import java.sql.SQLException; + /** * * @author Agnieszka @@ -36,17 +38,21 @@ public class Album extends Item { } @Override - public void insertToDB() { - d.insertAlbumQ(this); + public void insertToDB() throws SQLException { + try { + d.insertAlbumQ(this); + } catch (SQLException ex) { + throw new SQLException("Error dodawania albumu"); + } } @Override - public void delFromDB() { + public void delFromDB() throws SQLException { } @Override - public void editInDB() { + public void editInDB() throws SQLException { } diff --git a/src/library/AlbumFieldPattern.java b/src/library/AlbumFieldPattern.java index 3305d5d..0d0ce3e 100644 --- a/src/library/AlbumFieldPattern.java +++ b/src/library/AlbumFieldPattern.java @@ -5,6 +5,7 @@ */ package library; +import java.sql.SQLException; import javax.swing.JFrame; import javax.swing.JOptionPane; @@ -17,7 +18,6 @@ public class AlbumFieldPattern extends javax.swing.JFrame { /** * Creates new form bookFieldPattern */ - public AlbumFieldPattern() { this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); initComponents(); @@ -28,7 +28,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame { this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); albumTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required)); } - public boolean add = false, delete = false, edit = false, search=false; + public boolean add = false, delete = false, edit = false, search = false; /** * This method is called from within the constructor to initialize the form. @@ -174,15 +174,19 @@ public class AlbumFieldPattern extends javax.swing.JFrame { private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed if (this.add) { - Album a = new Album(0, albumTitle.getText(), musican.getText(), Integer.parseInt(year.getText()), Category.getSelectedItem().toString()); - a.insertToDB(); - this.dispose(); + try { + Album a = new Album(0, albumTitle.getText(), musican.getText(), Integer.parseInt(year.getText()), Category.getSelectedItem().toString()); + a.insertToDB(); + this.dispose(); + } catch (SQLException e) { + e.getMessage(); + } } else if (this.edit) { JOptionPane.showMessageDialog(null, "EDYTUJ"); } else if (this.delete) { JOptionPane.showMessageDialog(null, "USUŃ"); } - + }//GEN-LAST:event_SaveChangesActionPerformed private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed @@ -190,7 +194,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame { }//GEN-LAST:event_yearActionPerformed private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed - this.dispose(); + this.dispose(); }//GEN-LAST:event_cancelActionPerformed /** diff --git a/src/library/Book.java b/src/library/Book.java index 080db34..3d745ae 100644 --- a/src/library/Book.java +++ b/src/library/Book.java @@ -5,6 +5,10 @@ */ package library; +import java.sql.SQLException; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * * @author Agnieszka @@ -38,21 +42,25 @@ public class Book extends Item { tab[r][5] = b.getISBN(); tab[r][6] = b.getPublishing(); tab[r][7] = b.getCategory(); - return tab ; -} - -@Override - public void insertToDB() { - d.insertBookQ(this); + return tab; } @Override - public void delFromDB() { + public void insertToDB() throws SQLException { + try { + d.insertBookQ(this); + } catch (SQLException ex) { + throw new SQLException("Error dodawania ksiazki"); + } + } + + @Override + public void delFromDB() throws SQLException { } @Override - public void editInDB() { + public void editInDB() throws SQLException { } diff --git a/src/library/BookFieldPattern.java b/src/library/BookFieldPattern.java index 9c1b7ca..f337725 100644 --- a/src/library/BookFieldPattern.java +++ b/src/library/BookFieldPattern.java @@ -251,9 +251,13 @@ public class BookFieldPattern extends javax.swing.JFrame { private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed if (this.add) { - + try{ Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), Integer.parseInt(year.getText()), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString()); b.insertToDB(); + } + catch(SQLException e){ + e.getMessage(); + } } else if (this.edit) { JOptionPane.showMessageDialog(null, "EDYTUJ"); diff --git a/src/library/Database.java b/src/library/Database.java index 2ddec0f..ecd7be0 100644 --- a/src/library/Database.java +++ b/src/library/Database.java @@ -86,7 +86,7 @@ public class Database { return true; } - public void insertBookQ(Book b) { + public void insertBookQ(Book b) throws SQLException { try { PreparedStatement prepStmt = conn.prepareStatement( "INSERT INTO books VALUES (NULL, ?, ?, ?, ?, ?, ?, ?);"); @@ -99,16 +99,15 @@ public class Database { prepStmt.setString(7, b.getCategory()); prepStmt.execute(); JOptionPane.showMessageDialog(null, "Dodano poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE); - - } catch (SQLException e) { JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE); e.printStackTrace(); + throw new SQLException("Error dodawania ksiazki"); } } - public void insertAlbumQ(Album a) { + public void insertAlbumQ(Album a) throws SQLException { try { PreparedStatement prepStmt = conn.prepareStatement( "INSERT INTO albums VALUES (NULL, ?, ?, ?, ?);"); @@ -121,14 +120,15 @@ public class Database { } catch (SQLException e) { JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu albumu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE); e.printStackTrace(); + throw new SQLException("Error dodawania albumu"); } } - public void insertMovieQ(Movie m) { + public void insertMovieQ(Movie m) throws SQLException { try { PreparedStatement prepStmt = conn.prepareStatement( - "INSER INTO movies VALUES (NULL, ?, ?, ?, ?);"); + "INSERT INTO movies VALUES (NULL, ?, ?, ?, ?);"); prepStmt.setString(1, m.getName()); prepStmt.setString(2, m.getDirector()); prepStmt.setInt(3, m.getYear()); @@ -137,6 +137,8 @@ public class Database { JOptionPane.showMessageDialog(null, "Dodano poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE); } catch (SQLException e) { JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE); + e.printStackTrace(); + throw new SQLException("Error dodawania albumu"); } } @@ -250,7 +252,7 @@ public class Database { } } catch (IndexOutOfBoundsException e) { JOptionPane.showMessageDialog(null, "Baza danych pusta", "Error:", JOptionPane.INFORMATION_MESSAGE); - throw new IndexOutOfBoundsException("Nie mozna dzielić przez 0"); + throw new IndexOutOfBoundsException("Poza zakresem"); } return null; diff --git a/src/library/Item.java b/src/library/Item.java index 41a6665..980a050 100644 --- a/src/library/Item.java +++ b/src/library/Item.java @@ -5,6 +5,8 @@ */ package library; +import java.sql.SQLException; + /** * * @author Agnieszka @@ -12,11 +14,11 @@ package library; */ public abstract class Item { - public abstract void insertToDB(); + public abstract void insertToDB() throws SQLException ; - public abstract void delFromDB(); + public abstract void delFromDB() throws SQLException ; - public abstract void editInDB(); + public abstract void editInDB() throws SQLException ; public void setName(String s) { this.name = s; diff --git a/src/library/Movie.java b/src/library/Movie.java index 2d370f1..c276a11 100644 --- a/src/library/Movie.java +++ b/src/library/Movie.java @@ -45,17 +45,21 @@ public class Movie extends Item { } @Override - public void insertToDB() { - d.insertMovieQ(this); + public void insertToDB() throws SQLException { + try { + d.insertMovieQ(this); + } catch (SQLException ex) { + throw new SQLException("Error dodawania filmu"); + } } @Override - public void delFromDB() { + public void delFromDB() throws SQLException { String query = "DELETE FROM books WHERE id=" + this.getId() + ";"; } @Override - public void editInDB() { + public void editInDB() throws SQLException { } diff --git a/src/library/MovieFieldPattern.java b/src/library/MovieFieldPattern.java index 4bb7fa4..14c7aab 100644 --- a/src/library/MovieFieldPattern.java +++ b/src/library/MovieFieldPattern.java @@ -5,6 +5,7 @@ */ package library; +import java.sql.SQLException; import javax.swing.JFrame; import javax.swing.JOptionPane; @@ -27,7 +28,7 @@ public class MovieFieldPattern extends javax.swing.JFrame { this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); movieTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required)); } - public boolean add = false, delete = false, edit = false, search=false; + public boolean add = false, delete = false, edit = false, search = false; /** * This method is called from within the constructor to initialize the form. @@ -172,14 +173,19 @@ public class MovieFieldPattern extends javax.swing.JFrame { private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed if (this.add) { - Movie m = new Movie(0, movieTitle.getText(), director.getText(), Integer.parseInt(year.getText()), Category.getSelectedItem().toString() ); - m.insertToDB(); + try { + Movie m = new Movie(0, movieTitle.getText(), director.getText(), Integer.parseInt(year.getText()), Category.getSelectedItem().toString()); + m.insertToDB(); + this.dispose(); + } catch (SQLException e) { + e.getMessage(); + } } else if (this.edit) { JOptionPane.showMessageDialog(null, "EDYTUJ"); } else if (this.delete) { JOptionPane.showMessageDialog(null, "USUŃ"); } - this.dispose(); + }//GEN-LAST:event_SaveChangesActionPerformed private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed