0

I Have an array list.

ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("timestamp");
arrayList.add("Code");
arrayList.add("Banana");
arrayList.add("record_version");

For each String, i want to save it to the database.

for(String str : arrayList){
    Rec_table table = new Rec_table();
    table.set("Name", str);
    table.saveIt();
}

My expectation is the data will look like this,

Name:
timestamp
Code
Banana
record_version

But the data is saved, like this, (Alphabetical Order)

Name:
Banana
Code
record_version
timestamp

Why is that happening ?

1 Answers1

2

How do you know that data is stored in this order? Additionally, why do you care how DB stores your data? When you request any data from a database and do not provide order by, the DB will not be obligated to return data in any specific order. If you need to read data in a specific you must provide an order by <column name>. If you need to read data in the same order, you need to add another column with an increment, and then order by that column.

Additionally, this question is really not related to ActiveJDBC.

ipolevoy
  • 5,432
  • 2
  • 31
  • 46