我想在数据库中存储和检索double值,但是当我插入纬度值时我遇到了一个问题,它完全插入但是当我检索纬度值时,它得到0.0意味着null ....下面的代码
import com.play.findnearplace.FD;
public class Database extends SQLiteOpenHelper {
protected static final int DATABASE_VERSION = 1;
protected static final String DATABASE_NAME = "place";
protected static final String TABLE_NAME = "tbl_place";
public Database(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String createdb = "CREATE TABLE IF NOT EXISTS "
+ TABLE_NAME
+ "(id INTEGER PRIMARY KEY AUTOINCREMENT,title VARCHAR NOT NULL ,description TEXT NOT NULL , refereceid TEXT NOT NULL ,place_id TEXT NOT NULL, delat DOUBLE ,delon DOUBLE)";
db.execSQL(createdb);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF NOT EXISTS " + TABLE_NAME);
onCreate(db);
}
public void insertdata(String title,String decription,String refernce,String place_id,Double delat,Double delon){
SQLiteDatabase db=getWritableDatabase();
ContentValues v =new ContentValues();
Logger.i("Query",refernce);
v.put("title",title);
v.put("description",decription);
v.put("refereceid",refernce);
v.put("place_id",place_id);
v.put("delat",delat);//here value of delat="2252215.25"
v.put("delon",delon);
db.insert(TABLE_NAME,null, v);
db.close();
}
public void isLikedelete(int id) {
// TODO Auto-generated method stub
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_NAME, "id="+id, null);
db.close();
}
public void isLikealldelete() {
// TODO Auto-generated method stub
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_NAME,null, null);
//db.execSQL("delete from "+ TABLE_NAME);
db.close();
}
public void isLikeDeleteByRef(String place_id) {
// TODO Auto-generated method stub
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_NAME, "place_id="+"'"+place_id+"'", null);
db.close();
}
public List<FD> bookmarkdata(){
SQLiteDatabase db=getReadableDatabase();
List<FD> book=new ArrayList<FD>();
String query="select * from "+ TABLE_NAME;
Cursor c=db.rawQuery(query,null);
if(c.moveToFirst()){
do{
FD bookmark = new FD();
bookmark.setid(c.getInt(0));
bookmark.settitle(c.getString(1));
bookmark.setshort_title(c.getString(2));
bookmark.setreference(c.getString(3));
bookmark.setlat(c.getDouble(4));
bookmark.setlon(c.getDouble(5));
Logger.i("DAta",""+c.getDouble(4));//but here value getting c.getDouble(4)=0.0
book.add(bookmark);
}while(c.moveToNext());
}
db.close();
c.close();
return book;
}
public boolean checkdataexist(String place_id){
SQLiteDatabase db=getReadableDatabase();
String query="select id from "+ TABLE_NAME +" where place_id='"+place_id+"'";
Logger.i("Query",query);
Cursor c=db.rawQuery(query,null);
int count=c.getCount();
boolean status;
if (count==0){
status= false;
}else{
status= true;
}
db.close();
c.close();
return status;
}
}
在insertdata()方法中插入值很好,但是当我在bookmarkdata()方法中检索纬度值时,它让我为空(0.0)这里有什么问题?