File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
src/main/java/com/example Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -15,11 +15,12 @@ public static void listarEstados() {
1515 System .out .println ("Listando estados cadastrados no banco de dados" );
1616 try {
1717 Class .forName ("org.postgresql.Driver" );
18- var conn = DriverManager .getConnection ("jdbc:postgresql://localhost/meubanco" , "postgres" , "" );
19- var stm = conn .createStatement ();
20- var result = stm .executeQuery ("select * from estado" );
21- while (result .next ()) {
22- System .out .println (result .getString ("nome" ));
18+ try (var conn = DriverManager .getConnection ("jdbc:postgresql://localhost/meubanco" , "postgres" , "" )){
19+ var stm = conn .createStatement ();
20+ var result = stm .executeQuery ("select * from estado" );
21+ while (result .next ()) {
22+ System .out .println (result .getString ("nome" ));
23+ }
2324 }
2425 } catch (ClassNotFoundException | SQLException e ) {
2526 System .out .println ("Erro: " + e .getMessage ());
You can’t perform that action at this time.
0 commit comments