Hello to all good afternoon, I would like to help me know how I can develop my idea. I have some lists in a class I did to make the connection to a database. which is the following:
package pkgfinal;
import java.sql.*;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ConexionMySQL {
Connection co;
Statement stm;
public ConexionMySQL(){
try{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost/estaciones?user=admin&password=123";
Connection co = DriverManager.getConnection(url);
Statement stm1 = co.createStatement();
Statement stm2 = co.createStatement();
Statement stm3 = co.createStatement();
ResultSet l1 = stm1.executeQuery("select * from linea1");
ResultSet l2 = stm2.executeQuery("select * from linea2");
ResultSet l3 = stm3.executeQuery("select * from linea3");
LinkedList ln1 = new LinkedList();
LinkedList ln2 = new LinkedList();
LinkedList ln3 = new LinkedList();
while(l1.next())
ln1.addLast(l1.getString(3));
while(l2.next())
ln2.addLast(l2.getString(3));
while(l3.next())
ln3.addLast(l3.getString(3));
System.out.println("linea1: "+ln1);
System.out.println("linea2: "+ln2);
System.out.println("linea3: "+ln3);
}
catch(ClassNotFoundException exc){
exc.printStackTrace();
}
catch (SQLException ex) {
Logger.getLogger(ConexionMySQL.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
As we can see I do the query:
ResultSet l1 = stm1.executeQuery("select * from linea1");
That is where I absorb all the data and put them on my list, however. this is where I do not know how to extract, so to speak, just one of the columns of my table, for example in case I want to extract only the IDs from my table to use them in some other function or in some other class and thus be able to play and manipulate all the data of my table but each one separately. I hope you have made me understand. THANK YOU FOR YOUR HELP.