-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathApp.java
28 lines (25 loc) · 962 Bytes
/
App.java
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
package com.example;
import java.sql.DriverManager;
import java.sql.SQLException;
public class App {
public static void main(String[] args){
System.out.println();
System.out.println("Aplicação Java de Exemplo\n");
listarEstados();
}
public static void listarEstados() {
System.out.println("Listando estados cadastrados no banco de dados");
try {
Class.forName("org.postgresql.Driver");
try(var conn = DriverManager.getConnection("jdbc:postgresql://localhost/postgres", "gitpod", "")){
var stm = conn.createStatement();
var result = stm.executeQuery("select * from estado");
while(result.next()) {
System.out.println(result.getString("nome"));
}
}
} catch (ClassNotFoundException | SQLException e) {
System.out.println("Erro: " + e.getMessage());
}
}
}