I recently read about not using getters and setters in Java (e.g. When are getters and setters justified).
I do not know if this is actually the best way to do object oriented programming. Anyway, supposing that I do not use getters in my code, how can I store data on a relational db? When I started using Java two years ago I used to do something like the following:
public void createTitle(Title title) {
// ... some code here ...
String sql = "INSERT INTO titles (title_id, name) "
+ "VALUES (TITLES_SEQ.NEXTVAL,?)";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, title.getName()); // Here is the getter
preparedStatement.executeUpdate();
// ... other code here ...
}
How can I save the title
with its properties (name
, in this case) in my relational database if I do not have the title.getName()
getter? This is just an example, but I hope it makes sense.
Some related discussions: