-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