-2
我对登录页面有以下代码。如何测试我的SQL服务器连接?
我创建了以下获得在接收凭证框中输入的数据。
final String NameHere = HeldUser.getText().toString();
final String PasswordHere = HeldPasssword.getText().toString();
以下是我的查询,它们与我的数据库中的数据进行比较。
ArryList<String> names= null;
ArrayList<String> password = null;
try{
con = MyConnectionClass();
String query = null;
if(con == null){
z = "Check Your Internet Access!";
// I have a toast RIGHT HERE to that I figured would trigger
the connection was not successful..
Toast.makeText(Async.this, "Connection failures. Contact Administrator.", Toast.LENGTH_SHORT).show();
} else {
if (Condition that I know is being triggered){
MyQueryDeclaredEarlier = "select * from MyTable where Username = '"+NameHere+ "'and Password = '"+PasswordHere+"'";
// The above was written with the +NameHere+ and +PasswordHere+ variables
receive String from EditTextBoxes I have for gathering credentials
// The Columns (Username and Password) are correct and the tablename (Table)
is also, as is, in the SQL management database. (I exluded dbo.)
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(MyQueryDeclaredEarlier);
while (rs.next()){
names.add(0,rs.getString("Username"));
password.add(0,rs.getString("Password"));
}
// then I just compare the username variable (NameHere) contents to
// the string I got from the ResultSet (rs) and added to the ListArray (names)
at position 0.
// I think this where the problem is.
String FromQuery = names.get(0).toString();
if(NameHere.equals(FromQuery)){
z = "query successful"
isSuccess = true;
}
else{
z = "Invalid Query!";
isSuccess = false;
}
伊马漏下的其余部分'}的
它使返回isSuccess为假。
是他们的任何简单的方法来测试实际的连接? 我有两个模块附加到这个项目。包括适当的依赖关系,但我不确定他们是否没有发生任何其他事情,我无法看到或Android无法为我读取。帮帮我。
很明显,'NameHere.equals(FromQuery)'不评估为真。为什么不对它进行调试以查看你回来的价值?或者,是否有可能做任何日志记录? – Greg
我实际上想出了一些不同的东西。欣赏建议虽然!截至目前,我正在努力让sql驱动程序集成。可能要发布一个新问题。打了一下,看看我能得到什么。谢谢! –
请不要用“FIXED !!!!”回答你的问题。相反,制定一个很好的答案来解释你解决这个问题的步骤,以便将来的读者可以学习某些东西/得到他们正在寻找的帮助。 =) – Seth