从mysql数据库中通过列号而不是JAVA中的列名获取数据?

从mysql数据库中通过列号而不是JAVA中的列名获取数据?,java,mysql,sql,database,jdbc,Java,Mysql,Sql,Database,Jdbc,这是通过列名打印值, 但我需要通过列号打印值,那么如何打印呢?请帮忙 [注***所有记录均为整型。] ResultSet rs2 = stmt.executeQuery(table_retrive)) { while (rs2.next()) { int val1 = rs2.getInt("id"); int val2 = rs2.getInt("name");

这是通过列名打印值, 但我需要通过列号打印值,那么如何打印呢?请帮忙

[注***所有记录均为整型。]

          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);
这会奏效的

使用rs2.getInt(索引号)

并按照API文档获取更多信息:

假设您参考了此文档。但我认为这不是最佳实践。在你问这个问题之前,你看过API了吗?
 int val1 = rs2.getInt(1);