java - The index 2 is out of range -
preparedstatement preparedstatement = connectionstring().preparestatement( "select username dbo.logindetails username = ? , 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 "+ resultset.getstring(1)+"password "+resultset.getstring(2)); }
without
+"password "+resultset.getstring(2)
it works fine, printing username database throws error.
com.microsoft.sqlserver.jdbc.sqlserverexception: index 2 out of range.
select username .....................
you have 1 column in select
clause.
change
select username, yourpasswordcolumnname from......
Comments
Post a Comment