I am working on my first personal project to try and learn some fundamentals of postgresql and Java.
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.
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.
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 < 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");
}
}
ARRIVALS, including the data types of each column?