single row(record), which has just two columns namely "name" and "password".
So does anyone know how can I get the data in the second column using java.sql.ResultSet ?
ResultSet rs = stmnt.executeQuery("select * from user");
rs.next();
name = rs.getString("name");
The above code gives me the value in the first column in the first record. But now how can I get the value in the 2nd column in the first record ?
https://docs.oracle.com/javase/tutorial/jdbc/basics/retrieving.html
Thanks Mihai 👍
Not sure whether you've already fixed, but following general understanding of jdbc result sets may be helpful. ResultSet works as a data container, and as an iterator (or "cursor") at the same time. So when you're fetching data from result set with ".getString", you should think of it like "I'm reading columns of the row that ResultSet is currently point at". When you're done fetching all the rows you need, you should point cursor at next row by calling "rs.next()". Yes, it's very confusing design, but this is old and very widely used interface, so we have to live with it))
When you're done fetching all the "row" you need, you should point cursor at next row by calling "rs.next()". Do you mean column here instead of row in the first phrase ?
Yes, I meant columns, you're right)) you fetch column values, then call "next", and now the same result set object points to next row
Обсуждают сегодня