Uzupełnienie ciał metod klas Album Movie Book : update i delete dziedziczone z Item
This commit is contained in:
parent
24744e8948
commit
f3f203ec2e
BIN
Library.zip
BIN
Library.zip
Binary file not shown.
BIN
biblioteka.db
BIN
biblioteka.db
Binary file not shown.
@ -23,8 +23,7 @@ public class Album extends Item {
|
|||||||
Album(int id, String n, String m, String y, String c) {
|
Album(int id, String n, String m, String y, String c) {
|
||||||
try {
|
try {
|
||||||
this.setYear(Integer.parseInt(y));
|
this.setYear(Integer.parseInt(y));
|
||||||
}
|
} catch (NumberFormatException e) {
|
||||||
catch(NumberFormatException e){
|
|
||||||
this.setYear(0);
|
this.setYear(0);
|
||||||
}
|
}
|
||||||
this.setId(id);
|
this.setId(id);
|
||||||
@ -54,12 +53,12 @@ public class Album extends Item {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delFromDB() throws SQLException {
|
public void delFromDB() throws SQLException {
|
||||||
|
d.deleteQ(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void editInDB() throws SQLException {
|
public void editInDB() throws SQLException {
|
||||||
|
d.updateQ(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMusican(String s) {
|
public void setMusican(String s) {
|
||||||
|
@ -229,7 +229,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
|
|||||||
} else if (this.update) {
|
} else if (this.update) {
|
||||||
Album a = new Album(Integer.parseInt(idValue.getText()), albumTitle.getText(), musican.getText(), year.getText(), Category.getSelectedItem().toString());
|
Album a = new Album(Integer.parseInt(idValue.getText()), albumTitle.getText(), musican.getText(), year.getText(), Category.getSelectedItem().toString());
|
||||||
try {
|
try {
|
||||||
d.updateQ(a);
|
a.editInDB();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -62,12 +62,12 @@ public class Book extends Item {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delFromDB() throws SQLException {
|
public void delFromDB() throws SQLException {
|
||||||
|
d.deleteQ(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void editInDB() throws SQLException {
|
public void editInDB() throws SQLException {
|
||||||
|
d.updateQ(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPublishing(String s) {
|
public void setPublishing(String s) {
|
||||||
|
@ -311,7 +311,7 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
|||||||
} else if (this.update) {
|
} else if (this.update) {
|
||||||
try {
|
try {
|
||||||
Book b = new Book(Integer.parseInt(idValue.getText()), bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString());
|
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) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ public class ListResult extends javax.swing.JFrame {
|
|||||||
Book b = new Book();
|
Book b = new Book();
|
||||||
b.setId((Integer) table.getValueAt(selectedRowIndex, 0));
|
b.setId((Integer) table.getValueAt(selectedRowIndex, 0));
|
||||||
try {
|
try {
|
||||||
d.deleteQ(b);
|
b.delFromDB();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
System.out.println("błąd usuwania SQL");
|
System.out.println("błąd usuwania SQL");
|
||||||
}
|
}
|
||||||
@ -181,7 +181,7 @@ public class ListResult extends javax.swing.JFrame {
|
|||||||
Movie m = new Movie();
|
Movie m = new Movie();
|
||||||
m.setId((Integer) table.getValueAt(selectedRowIndex, 0));
|
m.setId((Integer) table.getValueAt(selectedRowIndex, 0));
|
||||||
try {
|
try {
|
||||||
d.deleteQ(m);
|
m.delFromDB();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
System.out.println("błąd usuwania SQL");
|
System.out.println("błąd usuwania SQL");
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ public class ListResult extends javax.swing.JFrame {
|
|||||||
Album a = new Album();
|
Album a = new Album();
|
||||||
a.setId((Integer) table.getValueAt(selectedRowIndex, 0));
|
a.setId((Integer) table.getValueAt(selectedRowIndex, 0));
|
||||||
try {
|
try {
|
||||||
d.deleteQ(a);
|
a.delFromDB();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
System.out.println("błąd usuwania SQL");
|
System.out.println("błąd usuwania SQL");
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package library;
|
package library;
|
||||||
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
@ -16,7 +15,6 @@ import javax.swing.JOptionPane;
|
|||||||
*/
|
*/
|
||||||
public class Movie extends Item {
|
public class Movie extends Item {
|
||||||
|
|
||||||
|
|
||||||
private String director;
|
private String director;
|
||||||
private Database d = new Database();
|
private Database d = new Database();
|
||||||
|
|
||||||
@ -27,8 +25,7 @@ public class Movie extends Item {
|
|||||||
Movie(int id, String n, String d, String y, String c) {
|
Movie(int id, String n, String d, String y, String c) {
|
||||||
try {
|
try {
|
||||||
this.setYear(Integer.parseInt(y));
|
this.setYear(Integer.parseInt(y));
|
||||||
}
|
} catch (NumberFormatException e) {
|
||||||
catch(NumberFormatException e){
|
|
||||||
this.setYear(0);
|
this.setYear(0);
|
||||||
}
|
}
|
||||||
this.setId(id);
|
this.setId(id);
|
||||||
@ -58,12 +55,12 @@ public class Movie extends Item {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delFromDB() throws SQLException {
|
public void delFromDB() throws SQLException {
|
||||||
String query = "DELETE FROM books WHERE id=" + this.getId() + ";";
|
d.deleteQ(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void editInDB() throws SQLException {
|
public void editInDB() throws SQLException {
|
||||||
|
d.updateQ(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDirector() {
|
public String getDirector() {
|
||||||
|
@ -224,7 +224,7 @@ public class MovieFieldPattern extends javax.swing.JFrame {
|
|||||||
} else if (this.update) {
|
} else if (this.update) {
|
||||||
Movie m = new Movie(Integer.parseInt(idValue.getText()), movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString());
|
Movie m = new Movie(Integer.parseInt(idValue.getText()), movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString());
|
||||||
try {
|
try {
|
||||||
d.updateQ(m);
|
m.editInDB();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user