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