Add query dla books albums i movies OK
This commit is contained in:
parent
f7ae927511
commit
b8c4e12d6f
Binary file not shown.
Binary file not shown.
@ -28,7 +28,7 @@ public class Book extends Item {
|
||||
|
||||
@Override
|
||||
public void insertToDB() {
|
||||
db.insertBookQ(this);
|
||||
d.insertBookQ(this);
|
||||
}
|
||||
|
||||
;
|
||||
@ -80,6 +80,6 @@ public void setPublishing(String s) {
|
||||
return this.ISBN;
|
||||
}
|
||||
private String authorName, authorSurname, publishing, ISBN;
|
||||
private Database db = new Database();
|
||||
private Database d = new Database();
|
||||
|
||||
}
|
||||
|
@ -123,6 +123,21 @@ public class Database {
|
||||
|
||||
}
|
||||
|
||||
public void insertMovieQ(Movie m) {
|
||||
try {
|
||||
PreparedStatement prepStmt = conn.prepareStatement(
|
||||
"INSER INTO movies VALUES (NULL, ?, ?, ?, ?);");
|
||||
prepStmt.setString(1, m.getName());
|
||||
prepStmt.setString(2, m.getDirector());
|
||||
prepStmt.setInt(3, m.getYear());
|
||||
prepStmt.setString(4, m.getCategory());
|
||||
prepStmt.execute();
|
||||
} catch (SQLException e) {
|
||||
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<Book> selectBooks() {
|
||||
List<Book> books = new LinkedList<Book>();
|
||||
try {
|
||||
|
@ -19,6 +19,7 @@ public class Movie extends Item{
|
||||
public Connection conn;
|
||||
public Statement stat;
|
||||
private String director;
|
||||
private Database d = new Database();
|
||||
|
||||
Movie(){
|
||||
//nothing to do there
|
||||
@ -34,17 +35,7 @@ public class Movie extends Item{
|
||||
}
|
||||
@Override
|
||||
public void insertToDB(){
|
||||
try {
|
||||
PreparedStatement prepStmt = conn.prepareStatement(
|
||||
"insert into movies values (NULL, ?, ?, ?, ?);");
|
||||
prepStmt.setString(1, this.getName());
|
||||
prepStmt.setString(2, this.getDirector());
|
||||
prepStmt.setInt(3, this.getYear());
|
||||
prepStmt.setString(4, this.getCategory());
|
||||
prepStmt.execute();
|
||||
} catch (SQLException e) {
|
||||
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||
} //String query = "INSERT INTO books VALUES(NULL, '" +this.getName() + "', '" + this.getAuthorName() + "', '" + this.getAuthorSurname() + "', '"+ this.getPublishing() + "', '"+ this.getYear() + "', '"+ this.getISBN() + "', '"+ this.getCategory() + "');";
|
||||
d.insertMovieQ(this);
|
||||
};
|
||||
|
||||
public String getDirector(){
|
||||
|
Loading…
Reference in New Issue
Block a user