0

我直接在我的数据库界面中执行了相同的查询,结果得到了两行......我想我也应该在这里得到同样的结果......但它只返回一个,第二个它说列索引超出范围 2> 1!!!

session= request.getSession();
String name=(String)session.getAttribute("user");

Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mutualfund", "root", "");


Statement statement = connection.createStatement();
String qry="SELECT `account_type_id` FROM `cust_accounts` WHERE `cust_id`=\""+name+"\"";
ResultSet rs =  statement.executeQuery(qry) ;


if(!rs.next())
{
    out.println("Server Down.. Please try again later ");
} 
else {
    String one=rs.getString(1);
    String two=rs.getString(2);
}
4

1 回答 1

1

您的代码不是要求两行,而是要求两列,而您的查询只提供一列。

if (!rs.next()) {
  out.println("nope");
} else {
  String one = rs.getString(1);
  String two = "";
  if (rs.next())
    two = rs.getString(1);
  }
}
于 2013-06-15T21:03:10.337 回答