我有这段代码:
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)