0

Hello,
i query data from database using jdbc, and there will be a lot of data.how can i solve 1 by 1 of the data?currently, my code just solve the last data.
this is the pseudo:

JDBC connection
  query data = ResultSet{userid,task_id}
  while (Resultset())
    userid, task_id
    count++
    end
  close ResultSet
end

for i<=count
  solve the task
end

i know something is wrong.do i need an array?what else instead of array?

Edited by ubi_ct83: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by ~s.o.s~
0

You need to create task objects when you are iterating over the resultset. These task objects can be then pushed inside a list. You can then use this list as you see fit i.e. to run the tasks etc.

// untested pseudocode
final ResultSet rs = stmt.executeQuery();
while(rs.next()) {
  // create new task object
  taskList.add(task);
}
// close resultset, statement and connection

// somewhere else
for(Task task : tasklist) {
  // execute task
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.