public boolean updateAuthor(int id, Author author) { conn = DBConnection.getConn().getConnection(); String query = "update tblauthor set name = ?, dateOfBirth = ?, description = ? , imageurl = ?" + "where id = ?"; try { PreparedStatement pr = conn.prepareStatement(query); pr.setString(1, author.getName()); pr.setDate(2, (Date) author.getDateOfBirth()); pr.setString(3, author.getDescription()); pr.setString(4, author.getImageLink()); pr.setInt(5, id); int i = pr.executeUpdate(); if (i != -1) { return true; } } catch (SQLException e) { e.printStackTrace(); } return false; }
public boolean addAuthor(Author author) { conn = DBConnection.getConn().getConnection(); String query = "insert into tblauthor values (?,?,?,?,?)"; PreparedStatement pr; try { pr = conn.prepareStatement(query); pr.setInt(1, author.getId()); pr.setString(2, author.getName()); pr.setDate(3, author.getDateOfBirth()); pr.setString(4, author.getDescription()); pr.setString(5, author.getImageLink()); int i = pr.executeUpdate(); if (i != -1) { return true; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; }