[英]Android Studio can't execute the same query two times?
我嘗試使用 android studio 對數據庫執行查詢。 該查詢第一次有效,但第二次無效。 我顯示了這兩個查詢,但它們沒有區別。 我找到了問題的位置:第二個查詢什么也沒返回。 我不知道為什么。
你能幫助我嗎?
這里是查詢:
SELECT
EMP_ID, EMP_MOT_DE_PASSE, EMP_NOM,EMP_PRENOM, EMP_MAIL, EMP_TELEPHONE
FROM EMPLOYE
WHERE EMP_IDENTIFIANT='Identifiant'
這里的代碼:
final ArrayList<String> finalQueryResult = new ArrayList<>();
AsyncTask.execute(new Runnable() {
@Override
public void run() {
try {
String myurl = "url";
myurl = myurl.replaceAll(" ", "%20");
URL url = new URL(myurl);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
connection.setDoOutput(true);
connection.getContent();
InputStream inputStream = connection.getInputStream();
if(!query.contains("INSERT") && !query.contains("DELETE") && !query.contains("UPDATE")) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String str = bufferedReader.readLine();
String result = str.substring(5,str.length()-6);
JSONArray queryResult = new JSONArray(result);
for (int i = 0; i < queryResult.length(); i++) {
String lineOfQuery = queryResult.getString(i).substring(1, queryResult.getString(i).length() - 1);
finalQueryResult.addAll(Arrays.asList(lineOfQuery.split("[,]")));
}
}
} catch (Exception e) {
e.printStackTrace();
}finally {
communication = 0;
}
}
});
好的,我找到了答案。
我的問題是我只有第一次加載的表演。 “更改窗口”的事實只是使程序沒有給我表演並第二次跳過查詢。
所以要解決這個問題,我只使用 AsyncTask 而不是由主線程等待。
希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.