package jdbc;

import java.sql.*;

/**
 * java.sql.Driver
 *
 * - Connection URL
 * To access db, we need to build connection URL to connect to the database
 * Composed of 3 parts separated by colon - jdbc:<database_driver_name>:<database detail,host, port etc.>
 *
 * - DriverManager, DataSource
 * Those 2 helper classes have factory method to create connection.
 *
 * - Closing connection
 * Resourced opened in try/with statement are closed automatically
 * Closing connection closes statements and resultsets as well
 * Closing statement closes its resultsets as well
 * ResultSet is automatically closed when new SQL is run on the same statement
 *
 */
public class ConnectionToDatabase {
    public static void main(String[] args) throws ClassNotFoundException {
        String connectionUrl = "jdbc:postgresql:devalto";

        // Required to load class for JDBC 3.0 or prior versions
        Class.forName("org.postgresql.Driver");

        try (Connection conn = DriverManager.getConnection(connectionUrl);
             Statement stmt = conn.createStatement();
             ResultSet rs = stmt.executeQuery("select name from table")) {

            while (rs.next())
                System.out.println(rs.getString(1));
        }
        catch(SQLException e){
            System.out.println(e.getMessage());
            System.out.println(e.getSQLState());
            System.out.println(e.getErrorCode());
        }
    }
}

@@ -396,17 +396,17 @@
 Resource
-d
+s
  opened 
@@ -415,23 +415,28 @@
  try
-/
+-
 with
- statement
+-resource block
  are
@@ -460,33 +460,33 @@
 ally%0A * Closing 
-c
+C
 onnection closes
@@ -486,17 +486,17 @@
  closes 
-s
+S
 tatement
@@ -501,23 +501,23 @@
 nts and 
-r
+R
 esult
-s
+S
 ets as w
@@ -531,17 +531,17 @@
 Closing 
-s
+S
 tatement
@@ -556,15 +556,15 @@
 its 
-r
+R
 esult
-s
+S
 ets 
@@ -649,16 +649,23 @@
 tatement
+ object
 %0A *%0A */%0A

Update ConnectionToDatabase.java