このようなcreatetable、insert、selectを行っているのですが、
selectした後にc.getStringしたいのですがwhere(mov)がfalseで中に入れません。
この下のコードは、sqlをlogcatで出力したものになります。
なぜ、データを取得できないのでしょうか?
sql文が間違えているのでしょうか?
13:19 sqlの問題は、h2databaseで、sql文が正しいかを確認したことで、解消しました。
//create tableをしてる、MyOpenHelperクラス
java
1//create table 2 public static final String CREATE_TABLE = 3 "create table near (data text,username text,comment text,id integer primary key," + 4 "latitude double,longitude double)"; 5 6///////改善したcreatetable//////////// 7create table nearsdb (data text,username text,comment text,latitude double,longitude double); 8
//insertの文と、下は、logから取得したsql文です。LocationActivity
java
1//insertの文 2String sql="insert into near (data,username,comment,latitude,longitude)" + 3 " values ('"+data+"','"+username+"','"+comment+"',"+latitude+","+longitude+");"; 4 5//insertのsqlをlogで出力 6 insert into near (data,username,comment,latitude,longitude) 7 values ('4/ 28 10:33: 27','tai','やにやゆさはゆゆら',35.6539782,139.6471526) 8 9///////////改善したinsert文//////////////// 10insert into nearsdb(data,username,comment,latitude,longitude) values ('4/ 28 1:4: 7','ta','にのやはさは',35.6539782,139.6471526);
//select文と、下は、logから取得したsqlです。LocationActivity
java
1//select文 2 String sql= "select data,username,comment from near " + 3 "where latitude - "+latitude+" <= "+clearlatitude+" and " 4 +latitude+" - latitude <= "+clearlatitude+ 5 " and longitude - "+longitude+" <= "+clearlongitude+" and " 6 +longitude+" - longitude <= "+clearlongitude+";"; 7 8 9//selectのsqlをlogで出力 10 String sql= "select data,username,comment from near " + 11 "where latitude - 35.6539782 <= 2.694944E-5 " + 12 "and 35.6539782 - latitude <= 2.694944E-5 " + 13 "and longitude - 139.6471526 <= 3.2899147E-4" + 14 " and 139.6471526 - longitude <= 3.2899147E-4"; 15 16 Cursor c = db.rawQuery(sql, null); 17 boolean mov = c.moveToFirst(); 18while (mov) { 19 20Log.v("whileにはいった",sql); 21textView.setText(String.format("%s %s : %s", c.getString(0), c.getString(1),c.getString(2))); 22 } 23 24///////////////改善したselect文//////////// 25select data,username,comment from nearsdb where latitude - 35.6539782 <= 2.694944E-5 and 35.6539782 - latitude <= 2.694944E-5 and longitude - 139.6471526 <= 3.2899147E-4 and 139.6471526 - longitude <= 3.2899147E-4; 26
回答1件
あなたの回答
tips
プレビュー