O'Reilly logo

Java 11 Cookbook by Mohamed Sanaulla, Nick Samoylov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

We will start with CRUD operations by using the PostgreSQL database and the class Person1:

public class Person1 {    private int id;    private int age;    private String name;    public Person1(){}  //Must be present, used by the framework    public Person1(int age, String name){        this.age = age;        this.name = name;    }    public int getId() { return id; }    public void setName(String name) { this.name = name; }    @Override    public String toString() {        return "Person1{id=" + id + ", age=" + age +                                  ", name='" + name + "'}";    }}

We need the previous getId() method to get an ID value (to demonstrate how to find a database record by ID). The method setName() will be used to update the database record, and the method toString() will be used to display the results. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required