我在我的数据库接口直接执行相同的查询,并得到两行作为结果…我想我在这里也应该得到相同的…但它只返回一个,第二个它说列索引超出范围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);
}
您的代码不是要求两行,而是要求两列,而您的查询只提供一个。
if (!rs.next()) {
out.println("nope");
} else {
String one = rs.getString(1);
String two = "";
if (rs.next())
two = rs.getString(1);
}
}