import java.util.InputMismatchException;
import java.util.Scanner;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;

public class Main {

    private static final Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {

        try {

            Class.forName("oracle.jdbc.driver.OracleDriver");

        } catch (ClassNotFoundException e) {

            System.out.println("Oracle JDBC Driver not found!");
            e.printStackTrace();
            System.exit(0);

        }

        System.out.println("Oracle JDBC Driver registered!");

        Connection connection = null;

        try {

            connection = DriverManager.getConnection(
                    "jdbc:oracle:thin:@toldb.oulu.fi:1521:toldb11", "STU31", "delrix123");

        } catch (SQLException e) {

            System.out.println("Connection failed!");
            e.printStackTrace();
            System.exit(0);

        }

        if (connection != null) {

            System.out.println("Connection to database successful!");

        } else {

            System.out.println("Failed to make connection!");
            System.exit(0);

        }

        System.out.print("\n\n");
        System.out.println("1: Show items.");
        System.out.println("2: Show customers.");
        System.out.println("3: Exit.");
        System.out.println("Make selection and press ENTER.");

        switch (getUserInput()) {

            case 1:
                showItems();
                break;

            case 2:
                showCustomers();
                break;

            case 3:
                try {

                    connection.close();
                    System.exit(0);

                } catch (SQLException e) {

                    System.out.println("Error while closing connection!");
                    e.printStackTrace();

                }

            default:
                System.out.println("Something went wrong!");
                System.exit(1);
        }

        try {

            connection.close();
            System.exit(0);

        } catch (SQLException e) {

            System.out.println("Error while closing connection!");
            e.printStackTrace();

        }
    }

    private static int getUserInput() {

        int choice = 0;

        while (true) {

            try {

                choice = scan.nextInt();

                if (choice != 1 && choice != 2 && choice != 3) {

                    scan.nextLine();
                    System.out.println("Please select 1, 2 or 3.");

                } else {

                    scan.nextLine();
                    break;

                }

            } catch (InputMismatchException ime) {

                System.out.println("Please select 1, 2 or 3.");
                scan.nextLine();

            }
        }

        return choice;
    }

    private static void showCustomers() {

    }

    private static void showItems() {

    }
}
@@ -9,61 +9,22 @@
 ava.
-util.InputMismatchException;%0Aimport java.util.Scanner
+sql.Connection
 ;%0Aim
@@ -56,36 +56,8 @@
 er;%0A
-import java.sql.Connection;%0A
 impo
@@ -81,16 +81,83 @@
 ception;
+%0Aimport java.util.InputMismatchException;%0Aimport java.util.Scanner;
 %0A%0Apublic
@@ -375,17 +375,16 @@
  %7D catch
- 
 (ClassNo
@@ -813,33 +813,32 @@
 %0A        %7D catch
- 
 (SQLException e)
@@ -978,17 +978,16 @@
       if
- 
 (connect
@@ -1441,17 +1441,16 @@
   switch
- 
 (getUser
@@ -1507,16 +1507,26 @@
 owItems(
+connection
 );%0A     
@@ -1540,66 +1540,30 @@
     
-break;%0A%0A            case 2:%0A                showCustomers(
+exitRoutine(connection
 );%0A 
@@ -1602,17 +1602,17 @@
    case 
-3
+2
 :%0A      
@@ -1613,38 +1613,58 @@
                 
-try %7B%0A
+showCustomers(connection);
 %0A               
@@ -1656,36 +1656,44 @@
                 
-    
+exitRoutine(
 connection.close
@@ -1678,39 +1678,32 @@
 utine(connection
-.close(
 );%0A             
@@ -1709,133 +1709,64 @@
     
- 
-   System.exit(0);%0A%0A                %7D catch (SQLException e) %7B%0A%0A                    System.out.println(%22Error while closing 
+break;%0A%0A            case 3:%0A                exitRoutine(
 conn
@@ -1763,34 +1763,32 @@
 utine(connection
-!%22
 );%0A             
@@ -1794,51 +1794,14 @@
     
-  
-  e.printStackTrace();%0A%0A                %7D
+break;
 %0A%0A  
@@ -1900,62 +1900,20 @@
     
-System.exit(1);%0A        %7D%0A%0A        try %7B%0A%0A            
+exitRoutine(
 conn
@@ -1922,15 +1922,8 @@
 tion
-.close(
 );%0A 
@@ -1933,175 +1933,43 @@
     
-    System.exit(0);%0A%0A        %7D catch (SQLException e) %7B%0A%0A            System.out.println(%22Error while closing connection!%22);%0A            e.printStackTrace();%0A%0A        %7D
+%7D%0A%0A        exitRoutine(connection);
 %0A   
@@ -2051,17 +2051,16 @@
    while
- 
 (true) %7B
@@ -2140,17 +2140,16 @@
       if
- 
 (choice 
@@ -2422,17 +2422,16 @@
  %7D catch
- 
 (InputMi
@@ -2645,16 +2645,37 @@
 stomers(
+Connection connection
 ) %7B%0A%0A   
@@ -2712,20 +2712,332 @@
 owItems(
-) %7B%0A
+Connection connection) %7B%0A%0A    %7D%0A%0A    private static void exitRoutine(Connection connection) %7B%0A%0A        try %7B%0A%0A            connection.close();%0A            System.exit(0);%0A%0A        %7D catch(SQLException e) %7B%0A%0A            System.out.println(%22Error while closing connection!%22);%0A            e.printStackTrace();%0A%0A        %7D
 %0A    %7D%0A%7D

exit routine