Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm writing simple Java code and I have to execute an SQL query on my Postgresql database. The result of this database (I've checked manually) is a simple table made by one column and two integer numbers, like this:

enter image description here

My problem is that I cannot find any way to read these two rows. My reading code is:

List< Short > lista = new List< Short >();

_rs = _stmt.executeQuery(query);

while (_rs.next()) {

lista.add((short)_rs.getInt(1));

}

This code only reads the 1st row, but there's no way to make it read the 2nd row. The Short list "lista" contains always 1 element. It's like if the ResultSet does not proceed in reading the second row...

How to read both the rows?

share|improve this question
 
What's the query look like? –  MadProgrammer 1 hour ago

2 Answers

It doesn't seem to be an issue with syntax. Do you also get one row when you run the query against the database? Perhaps you can post your SQL query too.

share|improve this answer

List is an interface, try using something like ArrayList

List< Short > lista = new ArrayList< Short >();

_rs = _stmt.executeQuery(query);

     while (_rs.next()) {

lista.add((short)_rs.getShort(1));

}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.