JDBC 应用程序 - 列索引超出范围,0 < 1

JDBC Application - Column Index out of range, 0 < 1

我有这段代码:

try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection con= DriverManager.getConnection(
                    "jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8","root","Icdjoil100"","root","Iconofcoil100");
            Statement stmt=con.createStatement();
            ResultSet rs=stmt.executeQuery("select user_id , user_name from t_user");
            while(rs.next()) {
                System.out.println(rs.getInt(0));
            }
            con.close();
        }catch(Exception e){
            e.printStackTrace();
        }

但是当 运行 示例时出现此错误:

java.sql.SQLException: Column Index out of range, 0 < 1.
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
    at com.mysql.jdbc.ResultSet.checkColumnBounds(ResultSet.java:684)
    at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:2621)
    at Test.main(Test.java:20)

JDBC(如 SQL)是基于 1 的 API。 IE。列索引从 1 开始。写入:

rs.getInt(1);

ResultSet.getInt()

columnIndex - the first column is 1, the second is 2, ...