dodawanie ok

This commit is contained in:
Agnieszka Janicka 2016-06-08 13:17:41 +02:00
parent 5f0fb40d46
commit 5a14e5604a
20 changed files with 75 additions and 38 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -8,6 +8,7 @@
<file>file:/D:/PROJEKT/Library/src/library/MainMenu.java</file>
<file>file:/D:/PROJEKT/Library/src/library/Item.java</file>
<file>file:/D:/PROJEKT/Library/src/library/Validation.java</file>
<file>file:/D:/PROJEKT/Library/src/library/Album.java</file>
<file>file:/D:/PROJEKT/Library/src/library/AlbumFieldPattern.java</file>
<file>file:/D:/PROJEKT/Library/src/library/Book.java</file>
<file>file:/D:/PROJEKT/Library/src/library/Database.java</file>

View File

@ -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() {
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 {
}

View File

@ -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();
@ -174,9 +174,13 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
if (this.add) {
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) {

View File

@ -5,6 +5,10 @@
*/
package library;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Agnieszka
@ -42,17 +46,21 @@ public class Book extends Item {
}
@Override
public void insertToDB() {
public void insertToDB() throws SQLException {
try {
d.insertBookQ(this);
} catch (SQLException ex) {
throw new SQLException("Error dodawania ksiazki");
}
}
@Override
public void delFromDB() {
public void delFromDB() throws SQLException {
}
@Override
public void editInDB() {
public void editInDB() throws SQLException {
}

View File

@ -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");

View File

@ -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;

View File

@ -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;

View File

@ -45,17 +45,21 @@ public class Movie extends Item {
}
@Override
public void insertToDB() {
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 {
}

View File

@ -5,6 +5,7 @@
*/
package library;
import java.sql.SQLException;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
@ -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) {
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