Похожие чаты

Suppose I have a table called "user" with just a

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 ?

6 ответов

16 просмотров

https://docs.oracle.com/javase/tutorial/jdbc/basics/retrieving.html

mito 😼- Автор вопроса

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))

mito 😼- Автор вопроса
Dmytro Buryak
Not sure whether you've already fixed, but followi...

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 ?

mito 😼
When you're done fetching all the "row" you need, ...

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

Похожие вопросы

Обсуждают сегодня

Если у меня есть такой класс: Object = {} function Object:new(a_name, a_transform, a_color, a_mesh, a_material, a_shader, a_textures) local private = {} private.n...
Cuarno Vile
4
А кто-то пробовал, уезжая из Эстонии получить э-рез и продолжить вести предпринимательскую деятельность внутри Эстонии, используя свой OÜ?
Lalalashechki Lalala
62
Is Kadena onto something special? No one really knows. Good luck!
Bright Uncle Stephen EqualBet
40
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
At which price point will BCH, an ASIC mined coin, be succeptible to reorg attacks because of low hashrate? $10? $1? $0.1? $0.01?
Kishniev
18
Гайз, кто-нибудь пробовал запустить probe-rs под камень, которого нет в probe-rs? Мб есть какой-нибудь пример у кого... Через target-gen попробовал сгенерировать chip-descript...
Максим Смирнов
2
зачем же переименовывать ? чтобы кол-во участников возросло или вдруг IBM от этого снова на свифте начнет кодить ? Я не понимаю что страшного в том что свифт гавно, если это т...
Oleh Nerzh
10
2 years ago I bought akt on Bittrex, at that time it gave a withdrawal option to the polygon network. I have read in this chat and they say that akt is not in polygon but if ...
TW
13
I'm new at Monero and I'd like to ask you all - why are you in Monero? I know about privacy but what do you expect to happen in the next years, decades that Monero will make i...
Konrad
13
I hodl ocean for a long time. Is there new development that I should read?
A33
12
Карта сайта