PreparedStatement preparedStatement = Connectionstring().prepareStatement(
"Select Username from dbo.LoginDetails where Username = ? and Password =?");
String User = tf_Fname.getText();
String _Pass = new String(tf_Lname.getPassword());
preparedStatement.setString(1, User);
preparedStatement.setString(2, _Pass);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
System.out.println("Username is "+ resultSet.getString(1)+"Password is "+resultSet.getString(2));
}
沒有該指數2超出範圍
+"Password is "+resultSet.getString(2)
它工作得很好,它從數據庫 打印的用戶名但它也拋出一個錯誤。
com.microsoft.sqlserver.jdbc.SQLServerException: The index 2 is out of range.
是不是你只需選擇用戶名?如果您只從數據庫中選擇一個項目,怎麼會有兩件事情? – sunrize920
+1感謝您的建議。 – anuj