-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.java
More file actions
33 lines (25 loc) · 907 Bytes
/
Copy pathMain.java
File metadata and controls
33 lines (25 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.sql.SQLException;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
//you need create database with this name 'github-example-jdbc'
String url = "jdbc:postgresql://localhost:5432/github-example-jdbc";
//user default
String user = "postgres";
//your password. root is default
String password = "root";
PersonJDBC pjdbc = new PersonJDBC(url, user, password);
Person person = new Person();
person.setName("Chloe");
person.setIdentity("ZAA21");
person.setBirthday("10/10/1980");
pjdbc.addPerson(person);
ArrayList<Person> array = pjdbc.getAllPersons();
for (Person i : array) {
System.out.println(i.getName()+ ", your id is "+ i.getId()+
", "+ i.getBirthday());
}
System.out.println(pjdbc.getPerson("Rafael").getName());
pjdbc.removePerson(person);
}
}