JDBC and PostgreSQL - how to insert int in same row based on another int
<p>I am working on my first personal project to try and learn some fundamentals of postgresql and Java.</p>

<p>I am trying to generate a randomly generated integers in a database with 45000 entries with int representing date and time using a for loop in the insert. I've managed to be able to do that part on my own and searching SX, but I ran into a problem.</p>

<p>If you can check out the code below, I would like to randomly generate an integer based on a previous field in the same row. For example, if my TIMEHST (which represents the hour of the time that a process starts) is randomly generated to be 8 on that row, I want my TIMEHED (which represents the hour of the time that a process ends) to be a random integer between (TIMEHST and TIMEHST+5). Please excuse me if the code below looks like spaghetti, I've only been coding for 5 months and Java for 1 month.</p>

<pre><code>package generateSamepleDataSet;

import java.sql.*;

/**
 * Created by jkyju_000 on 2/16/2016.
 */
public class GenerateProcessSqlDatabase {
    public static void main(String args[]) {
        Connection c = null;
        Statement stmt = null;
        try {
            Class.forName("org.postgresql.Driver");
            c = DriverManager
                    .getConnection("jdbc:postgresql://localhost:5432/postgres",
                            "postgres", "adfadf12");
            c.setAutoCommit(false);
            System.out.println("Opened database successfully");

            stmt = c.createStatement();

            for (int i = 0; i &lt; 45000; i++) {
                String sql = "INSERT INTO ARRIVALS (DATEY,DATEM,DATED,TIMEHST,TIMEMST,TIMEHED,TIMEMED) "
                        + "VALUES ( " + (2012 + (int)(Math.random() * ((2015 - 2012) + 1))) + ", " + (1 + (int)(Math.random() * ((12 - 1) + 1))) + ", " + (1 + (int)(Math.random() * ((30 - 1) + 1))) + ", " + (7 + (int)(Math.random() * ((19 - 1) + 1))) + ", " + (0 + (int)(Math.random() * ((59 - 0) + 1))) + ", "I have no idea what to put in TIMEHED", "Also have no idea what to put in TIMEMED" );";
                stmt.executeUpdate(sql);
            }

            stmt.close();
            c.commit();
            c.close();
        } catch (Exception e) {
            System.err.println( e.getClass().getName()+": "+ e.getMessage() );
            System.exit(0);
        }
        System.out.println("Records created successfully");
    }
}
</code></pre>