I need to get(retrieve) mysql databse data to java array list and print one by one using indexes...
I already tried normal do-while for retrieve, but i need to take values to array list...
public class Portdetails
{
public static void main(String[] args) {
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
try ( Connection cn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/airportinfo","root",""))
{
Statement smt=(Statement) cn.createStatement();
//query to display all records from table employee
String q="SELECT * FROM airportinfo";
//to execute query
ResultSet rs=smt.executeQuery(q);
//to print the resultset on console
if(rs.next()){
do{
System.out.println(rs.getString(1)+"--"+rs.getString(2)+"--"+rs.getString(3)+"--"+rs.getString(4));
}while(rs.next());
}
else{
System.out.println("Record Not Found...");
}
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}