如何使用数组更新表中的行

时间:2019-12-19 15:37:34

标签: android sqlite android-sqlite

我在处理以下问题时遇到困难:

for(int i = 1; i <= 100; i++) {  
    values.put("id", i);
    DB.update("book", values, "_id between 1 and 100", null);
}

非常抱歉,这是我的代码:

for(int i=0;i<strArray.length;i++){
values.put("id", strArray[i]);
DB.update("book", values, "_id between 1 and 100", null);
}

我想用strArray更新列ID,换句话说,我想在_id在1到100之间的列ID中添加所有strArray 再次抱歉

表中的结果:

enter image description here

有人可以帮我吗?

1 个答案:

答案 0 :(得分:1)

您的代码在Request URL: https://local.mydomain.com:8080/em/ Request Method: GET Status Code: 302 Moved Temporarily Remote Address: 192.168.56.102:8080 Referrer Policy: no-referrer-when-downgrade Connection: keep-alive Content-Language: en Content-Type: text/plain Date: Thu, 19 Dec 2019 14:48:23 GMT Location: https://local.mydomain.com:8080/em/em/login.jsp Server: nginx/1.15.8 Set-Cookie: ORA_SMP_EM_AUTH_27122419296023168200=YFEeoZWcMPfA8gQQ82F0czCIcgA5rumW3-u1gJZ8DZ0W8Zr6Uxpa!371330538; path=/em; domain=.mydomain.com; secure; HttpOnly Transfer-Encoding: chunked X-debug-message: Just for testing X-ORCL-EMOA: true Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9,pa;q=0.8 Cache-Control: no-cache Connection: keep-alive Cookie: ORA_SMP_EM_AUTH_27122419296023168200=ZY0aWFKYSHRDLT5NpsYrDVJ6lnMQbzAR5LGitj2FDX5zJExGpuFi!371330538; __cfduid=d490c5ed0fba5408abb5ffebaf9e1ad561548864527; _ga=GA1.2.147384809.1548864525 Host: local.mydomain.com:8080 Pragma: no-cache Sec-Fetch-Mode: navigate Sec-Fetch-Site: none Sec-Fetch-User: ?1 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 --------------------------------------------------------------------------------------------------------------------------------- Request URL: https://local.mydomain.com:8080/em/em/login.jsp Request Method: GET Status Code: 302 Moved Temporarily Remote Address: 192.168.56.102:8080 Referrer Policy: no-referrer-when-downgrade Connection: keep-alive Content-Language: en Content-Type: text/html; charset=UTF-8 Date: Thu, 19 Dec 2019 14:48:24 GMT Location: https://local.mydomain.com:8080/em/em/faces/logon/core-uifwk-console-login Server: nginx/1.15.8 Transfer-Encoding: chunked X-debug-message: Just for testing X-ORACLE-DMS-ECID: 005aWybD0OcE8T0_zxDCiW0001L^000NGP X-ORCL-EMOA: true Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9,pa;q=0.8 Cache-Control: no-cache Connection: keep-alive Cookie: ORA_SMP_EM_AUTH_27122419296023168200=YFEeoZWcMPfA8gQQ82F0czCIcgA5rumW3-u1gJZ8DZ0W8Zr6Uxpa!371330538; __cfduid=d490c5ed0fba5408abb5ffebaf9e1ad561548864527; _ga=GA1.2.147384809.1548864525 Host: local.mydomain.com:8080 Pragma: no-cache Sec-Fetch-Mode: navigate Sec-Fetch-Site: none Sec-Fetch-User: ?1 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 --------------------------------------------------------------------------------------------------------------------------------- Request URL: https://local.mydomain.com:8080/em/em/faces/logon/core-uifwk-console-login Request Method: GET Status Code: 200 OK Remote Address: 192.168.56.102:8080 Referrer Policy: no-referrer-when-downgrade Cache-Control: no-cache Connection: keep-alive Content-Encoding: gzip Content-Language: en Content-Type: text/html;charset=utf-8 Date: Thu, 19 Dec 2019 14:48:24 GMT Expires: Thu, 01 Jan 1970 00:00:00 GMT Server: nginx/1.15.8 Transfer-Encoding: chunked Vary: Accept-Encoding X-debug-message: Just for testing X-ORACLE-DMS-ECID: 005aWybE49ZE8T0_zxDCiW0001L^000Ma1 X-ORCL-EMOA: true Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9,pa;q=0.8 Cache-Control: no-cache Connection: keep-alive Cookie: ORA_SMP_EM_AUTH_27122419296023168200=YFEeoZWcMPfA8gQQ82F0czCIcgA5rumW3-u1gJZ8DZ0W8Zr6Uxpa!371330538; __cfduid=d490c5ed0fba5408abb5ffebaf9e1ad561548864527; _ga=GA1.2.147384809.1548864525 Host: local.mydomain.com:8080 Pragma: no-cache Sec-Fetch-Mode: navigate Sec-Fetch-Site: none Sec-Fetch-User: ?1 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 --------------------------------------------------------------------------------------------------------------------------------- Request URL: https://local.mydomain.com:8080/em/em/faces/logon/core-uifwk-console-login?_afrLoop=5008527327684549&_afrWindowMode=2&Adf-Window-Id=w0 Request Method: GET Status Code: 200 OK Remote Address: 192.168.56.102:8080 Referrer Policy: no-referrer-when-downgrade Cache-Control: no-cache Connection: keep-alive Content-Encoding: gzip Content-Language: en Content-Type: text/html;charset=utf-8 Date: Thu, 19 Dec 2019 14:48:24 GMT Expires: Thu, 01 Jan 1970 00:00:00 GMT Server: nginx/1.15.8 Transfer-Encoding: chunked Vary: Accept-Encoding X-debug-message: Just for testing X-ORACLE-DMS-ECID: 005aWybFUTEE8T0_zxDCiW0001L^000Ma2 X-ORCL-EMOA: true Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9,pa;q=0.8 Cache-Control: no-cache Connection: keep-alive Cookie: ORA_SMP_EM_AUTH_27122419296023168200=YFEeoZWcMPfA8gQQ82F0czCIcgA5rumW3-u1gJZ8DZ0W8Zr6Uxpa!371330538; __cfduid=d490c5ed0fba5408abb5ffebaf9e1ad561548864527; _ga=GA1.2.147384809.1548864525 Host: local.mydomain.com:8080 Pragma: no-cache Referer: https://local.mydomain.com:8080/em/em/faces/logon/core-uifwk-console-login Sec-Fetch-Mode: navigate Sec-Fetch-Site: same-origin Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 _afrLoop: 5008527327684549 _afrWindowMode: 2 Adf-Window-Id: w0 --------------------------------------------------------------------------------------------------------------------------------- 循环的每个迭代中更新表中所有行,其中for的1到100。
每次迭代都使用变量{{1 }}更新所有这些行的列_id,您将看到最终结果,其最终值为i,即id
如果要用i用行中的值100更新id列,则更改为:

x

或使用占位符更好:

_id = x

或带有单个语句:

for(int i = 1; i <= 100; i++) {  
    values.put("id", i);
    DB.update("book", values, "_id = " + i, null);
}