return author;
}
public int update(Author author){
//how to update only changed fields ?
DbHelper dbHelper = new DbHelper();
Connection conn = dbHelper.getConnection();
String query = "UPDATE `authors` SET `full_name` = ?, `location` = ? , `age` = ? ,`details` = ? WHERE `id` = ?;";
int inserted_flag = 0;
PreparedStatement prepStmt = null;
try {
prepStmt = conn.prepareStatement(query);
prepStmt.setString(1, author.getFull_name());
prepStmt.setString(2, author.getLocation());
prepStmt.setInt(3, author.getAge());
prepStmt.setString(4, author.getDetails());
prepStmt.setInt(5,author.getId());
inserted_flag = prepStmt.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(Author.class.getName()).log(Level.SEVERE, null, ex);
} finally {
dbHelper.closeAllConnections(conn, prepStmt, null);
}
return inserted_flag;
}