0

SQL db

Refer the image.

I am new to Java.So in the table I want var x to point to first row.Initially var y should also point to first row.I want to just update y variable to next row in the while loop every time keeping x static until x and y matches.In the else part once value of y changes I need to update x to new value which matches y.How to do so?

var x= Initial;//dont know how to capture value over here.
while(rs.next){
var y=rs.getInt(1);
if(y==x){
 }
else{}
Aziz
  • 23
  • 6

2 Answers2

0

Try this :

    int x= 0;
    while(rs.next){
        if (x == 0){
            x=rs.getInt(1);
        }
        int  y = rs.getInt(1);
        if(y !=x){
            x=y;
        }
    }
Sarangan
  • 868
  • 1
  • 8
  • 24
0

you can get the values from a resultSet as below:

while(result.next()) {

    result.getString("columnName");
    result.getInt("columnName");
}

Or

while (resultSet.next()) {
            ResultSetMetaData metaData = resultSet.getMetaData();
            int columnCount = metaData.getColumnCount();
            for (int i = 0; i < columnCount; i++) {
                resultSet.getObject(i);
            }
        }
Prog_G
  • 1,539
  • 1
  • 8
  • 22