I'm using the following code for getting values from ArrayList and adding into database. I'm using PreparedStatement and my database is Oracle.
ps = conn.prepareStatement("insert into Employee values(?,?,?,?,?)");
for (Employee e : elist) {
ps.setInt(1, e.getEmployeeId());
ps.setString(2, e.getEmployeeName());
ps.setString(3, e.getGender());
ps.setString(4, e.getDesignation());
ps.setString(5, e.getEmail());
added += ps.executeUpdate();
}
elist is an ArrayList of Employees.
here is the code for preparing the ArrayList:
Employee e1 = new Employee(1,"I","M","AS","[email protected]");
Employee e2 = new Employee(2,"A","M","RS","[email protected]");
Employee e3 = new Employee(3,"S","F","SD","[email protected]");
Employee e4 = new Employee(4,"SS","F","SD","[email protected]");
ArrayList<Employee> elist = new ArrayList<Employee>();
elist.add(e1);
elist.add(e2);
elist.add(e3);
elist.add(e4);
I've uploaded of the Employee table after insertion:
As you can see, the rows are not inserted as per the sequence of primary key i.e. Employee_Id values.I mean to say, when the data is inserted, the rows are normally expected to be in the sequence 1,2,3,4 . But it's not the case here.
I might have missed some very basic point in this, but I I've just begin with JDBC stuff.

order bywhen retrieving the data the database is free to return them in any order it likes.