package ru.aserdyuchenko.JDBC;

import java.sql.*;

/**
 * @author Anton Serdyuchenko. anton415@gmail.com
 * TODO shift all .close() in finally.
 * TODO add method create table.
 * TODO add since tag in javaDoc.
 */
public class JdbcStorage {
    private final Connection connection;

    /**
     * Constructor.
     */
    public JdbcStorage() {
        final Settings settings = Settings.getInstance();
        try {
            this.connection = DriverManager.getConnection(
                    settings.value("jdbc.url"),
                    settings.value("jdbc.username"),
                    settings.value("jdbc.password"));
        } catch (SQLException e) {
            throw new IllegalStateException(e);
        } finally {

        }
    }

    /**
     * Print all numbers in table.
     */
    public void print() {
        try (final Statement statement = this.connection.createStatement();
            final ResultSet rs = statement.executeQuery("select * from test")) {
            while (rs.next()) {
                System.out.println(String.format("%s", rs.getInt("number")));
            }
            rs.close();
            statement.close();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {

        }
    }

    /**
     * Delete all frome table "test".
     */
    public void delete() {
        try {
            final Statement statement = this.connection.createStatement();
            statement.execute("delete from test");
            statement.close();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {

        }
    }

    /**
     * Add numbers in table. From 1 to N.
     * @param n - count numbers.
     */
    public void add(int n) {
        delete();
        try (final PreparedStatement statement = this.connection.prepareStatement("insert into test values(?)")) {
            for (int i = 1; i <= n; i++) {
                statement.setInt(1, i);
                statement.executeUpdate();
            }
            statement.close();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {

        }
    }

    /**
     * Check if table exist.
     */
    public boolean ifTableExist() {
        try {
            DatabaseMetaData md = connection.getMetaData();
            md.getTables(null, null, "test", null);
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        } finally {

        }
    }
}

@@ -43,16 +43,67 @@
 a.sql.*;
+%0Aimport java.util.ArrayList;%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -1310,32 +1310,622 @@
        %7D%0A    %7D%0A%0A
+    /**%0A     * Get all data from table.%0A     */%0A    public List%3CInteger%3E get() %7B%0A        List%3CInteger%3E list = new ArrayList%3C%3E();%0A        try (final Statement statement = this.connection.createStatement();%0A            final ResultSet rs = statement.executeQuery(%22select * from test%22)) %7B%0A            while (rs.next()) %7B%0A                list.add(rs.getInt(%22number%22));%0A            %7D%0A            rs.close();%0A            statement.close();%0A            return list;%0A        %7D catch (SQLException e) %7B%0A            e.printStackTrace();%0A            return null;%0A        %7D finally %7B%0A%0A        %7D%0A    %7D%0A%0A
     /**%0A     * D
@@ -3159,10 +3159,9 @@
 %7D%0A    %7D%0A
+
 %7D
-%0A

Add method get in JdbcStorage.java. Add package-info.java. Add XmlStorage.java. Remove SQL_comands.sql. Remove SQLStorage.java.