0

This is printing the values through column name, But I need to print the values through column number, Then how ? Please help.

[Note*** All the record are int type.]

          ResultSet rs2 = stmt.executeQuery(table_retrive)) {

                while (rs2.next()) {
                    int val1 = rs2.getInt("id");
                    int val2 = rs2.getInt("name");
                    int val3 = rs2.getInt("job");
                    System.out.println(id+"   "+name+"    "+job);
  • suppose you refer this [post](https://stackoverflow.com/questions/186799/resultset-retrieving-column-values-by-index-versus-retrieving-by-label). but I think it's not best practice. – Rajith Pemabandu Jun 12 '17 at 00:36
  • Have you even looked at the [`ResultSet`](http://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html) API before you asked this question? – Mark Rotteveel Jun 12 '17 at 08:05

2 Answers2

0
 int val1 = rs2.getInt(1);

This will work.

https://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html

0

Use rs2.getInt(index number).

And follow the API documentation for more information:https://docs.oracle.com/javase/8/docs/api/java/sql/package-summary.html

Lakshman Miani
  • 344
  • 1
  • 5
  • 20