Android 開発で、sqlite(DB)を使用することがあります。
抽出時(select命令)、検索条件を検索の都度変更したいときがあります。
select命令で、可変変数を使用する際の方法をまとめました。
Wtabel・・・テーブル名
Wtime・・・何かしらの条件で設定した時刻
1 | String Wtabel; |
2 | String Wtime; |
3 |
4 |
5 | Wtabel = "xxxdb" ; |
6 |
7 | if (xxxxxxx < xxxx){ |
8 | Wtime = "1234" ; |
9 | } else { |
10 | Wtime = "1456" ; |
11 |
12 | } |
13 |
14 | String qry = "SELECT time,ride,ikisaki from " + Wtabel + " where time >= '" + Wtime + "' order by time" ; |