
Hello and namaste guys, i really need help here.i use ResultSet to query data from database. as we know, it query row by row using while (ResultSet()) this means, i have a lot of row.row means task.in each task, there will be an information like userid, Taskid, user_input
i have to use the information for eash task to solve the task it self.the problem im facing now is the code is just solve for the last data in result set.what should i do so that the solve code solve data 1 by 1?do i need to use array?what kind of array?

import java.sql.*;
import java.util.*;
class Retrieve{
public static void main(String[] args){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from employee");
ArrayList name=new ArrayList();
ArrayList address=new ArrayList();
ArrayList contact=new ArrayList();
ArrayList email=new ArrayList();
while(rs.next()){
name.add(rs.getString("name"));
address.add(rs.getString("address"));
contact.add(rs.getInt("contactNo"));
email.add(rs.getString("email"));
}
for(int i=0;i<name.size();i++){
System.out.println(name.get(i)+"\t"+address.get(i)+"\t"+contact.get(i)+"\t"+email.get(i));
}
}
catch(Exception e){
System.out.println(e);
}
}
}

using arraylist makes me more problem because i need to pass the value to the constructor.ive tried to change to single array,but got error.cannot find symbol constructor...
for(int i=0;i<count;i++)
{
String user_input = input[i];
int t_number = t_num[i];
String user_id = id[i];
int taskid = task_id[i];
Tway gen = new Tway(user_input , t_number , user_id , taskid);
gen.solve();
}
whats ive done wrong?
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.