Похожие чаты

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 ответов

37 просмотров

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

bWl0bw==- Автор вопроса

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

bWl0bw==- Автор вопроса
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 ?

bWl0bw==
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

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

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

Ready for some fun AND a chance to win TKO Tokens? Join us for exciting minigames in our Telegram group! 🕒 Don’t miss out—games start on today 25 October 2024, at 8 PM! Ge...
Milkyway | Tokocrypto
255
Мужики и девушки, привет) в Вelphi xe7 в настройках во вкладке "Editor Options" далее " Color" есть список: "Elements", открыв который мы можем настраивать отображение разных...
Kraszx
14
is that okay?
Samurai 🇯🇵
21
Добрый вечер. Есть вопрос, а может и предложение. Был у меня диалог в другой группе о делфи и я задался вопросом: "А нельзя ли в делфи цвет //коментария и {комментария} сде...
Kraszx
24
How about the project bro Likes the community not that active ?
🅿️abby_FX
19
Guys, Donald Trump or Kamala Harris? It does not matter for Bitcoin in the long run!! 2020 Election: After Joe Biden's victory in November 2020, Bitcoin steadily rose from...
Sabah Shabu
1
как быть с принтером? такой подход прокатит?
zamtmn
12
Всем привет! Подскажи, пожалуйста, как передать в TComboBox сразу значение и id записи. На Delphi я делал так: ComboBox1.Items.AddObject('Какое-то значение', Pointer(id запис...
Евгений
13
Мдя, прикол, боевая сборка запускается (именно под отладчиком) после F9 примерно полторы минуты (97 секунд если быть точным). Начал копать - проблема детектится сразу - зависа...
Александр (Rouse_) Багель
38
@brucezli Any info regarding ETA on updates?
Old Man Tom
10
Карта сайта