package ru.apetrov.JDBC;

import java.sql.*;

/**
 * Created by Andrey on 14.11.2017.
 */
public class WorkerJDBC {

    private Connection connection;
    private Statement statement;
    private PreparedStatement preparedStatement;
    private long n;

    public WorkerJDBC(long n) {
        this.n = n;
    }

    public void run() {
        try {
            connection = DriverManager.getConnection("jdbc:sqlite:H:\\java\\sqlite\\numbers.db");
            this.statement = connection.createStatement();
            this.statement.executeUpdate("CREATE TABLE IF NOT EXISTS test(field integer NOT NULL)");
            this.statement.executeUpdate("DELETE FROM test");
            connection.close();
            this.insertToTable(this.n);
            ResultSet res = this.statement.executeQuery("select field from test");
            while (res.next()) {
                System.out.println(res.getInt("field"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    private void insertToTable(long n) throws SQLException {
        preparedStatement = this.connection.prepareStatement("INSERT INTO test(field) VALUES (?)");
        for (int i = 1; i <= n; i++){
            preparedStatement.setInt(1, i);
        }
    }

    public static void main(String[] args) {
        WorkerJDBC workerJDBC = new WorkerJDBC(10);
        workerJDBC.run();
    }
}

@@ -149,90 +149,8 @@
 on;%0A
-    private Statement statement;%0A    private PreparedStatement preparedStatement;%0A
     
@@ -365,37 +365,42 @@
 %22);%0A            
-this.
+Statement 
 statement = conn
@@ -429,37 +429,32 @@
 ();%0A            
-this.
 statement.execut
@@ -504,15 +504,15 @@
 eld 
-integer
+INTEGER
  NOT
@@ -533,21 +533,16 @@
         
-this.
 statemen
@@ -582,40 +582,8 @@
 %22);%0A
-            connection.close();%0A
     
@@ -609,16 +609,28 @@
 ToTable(
+connection, 
 this.n);
@@ -658,21 +658,16 @@
 t res = 
-this.
 statemen
@@ -686,25 +686,25 @@
 ry(%22
-select
+SELECT
  field 
-from
+FROM
  tes
@@ -1092,16 +1092,39 @@
 ToTable(
+Connection connection, 
 long n) 
@@ -1145,33 +1145,33 @@
 ption %7B%0A        
-p
+P
 reparedStatement
@@ -1175,15 +1175,20 @@
 ent 
-= this.
+statement = 
 conn
@@ -1304,17 +1304,9 @@
     
-preparedS
+s
 tate
@@ -1324,16 +1324,55 @@
 (1, i);%0A
+            statement.executeUpdate();%0A
         

add JDBC