Uzupełnienie ciał metod klas Album Movie Book : update i delete dziedziczone z Item

This commit is contained in:
Agnieszka Janicka 2016-06-11 21:22:53 +02:00
parent 24744e8948
commit f3f203ec2e
9 changed files with 18 additions and 22 deletions

Binary file not shown.

Binary file not shown.

View File

@ -21,10 +21,9 @@ public class Album extends Item {
public Database d = new Database();
Album(int id, String n, String m, String y, String c) {
try{
this.setYear(Integer.parseInt(y));
}
catch(NumberFormatException e){
try {
this.setYear(Integer.parseInt(y));
} catch (NumberFormatException e) {
this.setYear(0);
}
this.setId(id);
@ -54,12 +53,12 @@ public class Album extends Item {
@Override
public void delFromDB() throws SQLException {
d.deleteQ(this);
}
@Override
public void editInDB() throws SQLException {
d.updateQ(this);
}
public void setMusican(String s) {

View File

@ -229,7 +229,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
} else if (this.update) {
Album a = new Album(Integer.parseInt(idValue.getText()), albumTitle.getText(), musican.getText(), year.getText(), Category.getSelectedItem().toString());
try {
d.updateQ(a);
a.editInDB();
} catch (SQLException e) {
e.printStackTrace();
}

View File

@ -62,12 +62,12 @@ public class Book extends Item {
@Override
public void delFromDB() throws SQLException {
d.deleteQ(this);
}
@Override
public void editInDB() throws SQLException {
d.updateQ(this);
}
public void setPublishing(String s) {

View File

@ -311,7 +311,7 @@ public class BookFieldPattern extends javax.swing.JFrame {
} else if (this.update) {
try {
Book b = new Book(Integer.parseInt(idValue.getText()), bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString());
d.updateQ(b);
b.editInDB();
} catch (SQLException e) {
e.printStackTrace();
}

View File

@ -173,7 +173,7 @@ public class ListResult extends javax.swing.JFrame {
Book b = new Book();
b.setId((Integer) table.getValueAt(selectedRowIndex, 0));
try {
d.deleteQ(b);
b.delFromDB();
} catch (SQLException ex) {
System.out.println("błąd usuwania SQL");
}
@ -181,7 +181,7 @@ public class ListResult extends javax.swing.JFrame {
Movie m = new Movie();
m.setId((Integer) table.getValueAt(selectedRowIndex, 0));
try {
d.deleteQ(m);
m.delFromDB();
} catch (SQLException ex) {
System.out.println("błąd usuwania SQL");
}
@ -189,7 +189,7 @@ public class ListResult extends javax.swing.JFrame {
Album a = new Album();
a.setId((Integer) table.getValueAt(selectedRowIndex, 0));
try {
d.deleteQ(a);
a.delFromDB();
} catch (SQLException ex) {
System.out.println("błąd usuwania SQL");
}

View File

@ -5,7 +5,6 @@
*/
package library;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
@ -16,7 +15,6 @@ import javax.swing.JOptionPane;
*/
public class Movie extends Item {
private String director;
private Database d = new Database();
@ -25,10 +23,9 @@ public class Movie extends Item {
}
Movie(int id, String n, String d, String y, String c) {
try{
this.setYear(Integer.parseInt(y));
}
catch(NumberFormatException e){
try {
this.setYear(Integer.parseInt(y));
} catch (NumberFormatException e) {
this.setYear(0);
}
this.setId(id);
@ -58,12 +55,12 @@ public class Movie extends Item {
@Override
public void delFromDB() throws SQLException {
String query = "DELETE FROM books WHERE id=" + this.getId() + ";";
d.deleteQ(this);
}
@Override
public void editInDB() throws SQLException {
d.updateQ(this);
}
public String getDirector() {

View File

@ -224,7 +224,7 @@ public class MovieFieldPattern extends javax.swing.JFrame {
} else if (this.update) {
Movie m = new Movie(Integer.parseInt(idValue.getText()), movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString());
try {
d.updateQ(m);
m.editInDB();
} catch (SQLException e) {
e.printStackTrace();
}