package com.github.javadev.orderdatabase;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DatabaseService {
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://localhost/test";

    static final String USER = "username";
    static final String PASS = "password";

    public List<Map<String, Object>> readAll() {
        List<Map<String, Object>> result = Collections.emptyList();
        Connection conn = null;
        Statement stmt = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(DB_URL, USER, PASS);
            stmt = conn.createStatement();

            String sql = "SELECT id, first, last, age FROM Registration";
            try (ResultSet resultSet = stmt.executeQuery(sql)) {
                while (resultSet.next()) {
                    int id = resultSet.getInt("id");
                    int age = resultSet.getInt("age");
                    String first = resultSet.getString("first");
                    String last = resultSet.getString("last");
                    
                    //Display values
                    System.out.print("ID: " + id);
                    System.out.print(", Age: " + age);
                    System.out.print(", First: " + first);
                    System.out.println(", Last: " + last);
                }
            }
        } catch (SQLException | ClassNotFoundException  se) {
            Logger.getLogger(DatabaseService.class.getName()).log(Level.SEVERE, null, se);
        } finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException se) {
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException se) {
            }
        }
        return result;
    }
}

@@ -36,16 +36,82 @@
 abase;%0A%0A
+import com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException;%0A
 import j
@@ -541,12 +541,15 @@
 ost/
-test
+orderdb
 %22;%0A%0A
@@ -584,16 +584,12 @@
  = %22
-username
+root
 %22;%0A 
@@ -623,16 +623,8 @@
  = %22
-password
 %22;%0A%0A
@@ -1044,20 +1044,17 @@
 ROM 
-Registration
+orderdata
 %22;%0A 
@@ -1768,24 +1768,414 @@
 tion  se) %7B%0A
+            if (se instanceof MySQLSyntaxErrorException) %7B%0A                String detailMessage = ((MySQLSyntaxErrorException) se).getMessage();%0A                if (detailMessage.contains(%22orderdata' doesn't exist%22)) %7B%0A//                    createTable();%0A                    Logger.getLogger(DatabaseService.class.getName()).log(Level.SEVERE, %22I am here%22);%0A                %7D%0A            %7D%0A
             

Add error check while connect to the database.