I've learned some MySQL recently and now I'm trying to work with a database in Java. Today I've faced a problem of retrieving data from the whole column. I already know, that if i do like:
ResultSet res = st.executeQuery("SELECT * FROM table_name WHERE id = n");
I get the whole raw. And then using
ResultSetMetaData metadata = res.getMetaData();
int colCount = metadata.getColumnCount();
while (res.next()) {
for (int i = 1; i <= colCount; i++){
String colValue = res.getString(i);
System.out.println(colValue);
}
}
I can sysout all values of the columns of this raw.
Now I have this
ResultSet res = st.executeQuery("SELECT column_name FROM table_name");
So I get one column and I need to iterate through it and sysout all the values.
Thanks in advance! :)