displaying the database and creating the database in android
i want to display the database with 3 columns latitude,longitude and addresss. i tried using cursors but the application crashes. i am writing the listener for button in onlocationchanged method. the button is save geopoint it updates the latitude,longitude and address of user. i also have a button named find geopoint which is used to display the database. here is my code. i wrote this in onlocationchanged.
try{
db.execSQL("CREATE TABLE "+Geo_Create_Table+" (Latitude INTEGER,Longtitude INTEGER ,ID INTEGER);");
}
catch(Exception e){
e.printStackTrace();
}
try{
开发者_JAVA技巧 db.execSQL("INSERT INTO "+Geo_Create_Table +" VALUES (" +lat +"," +lon +","+1+");");
}
catch (Exception e) {
}
and i used cursor to display the database but the problem persists pls help
db.execSQL("CREATE TABLE "+Geo_Create_Table+" (Latitude INTEGER,Longtitude INTEGER ,ID INTEGER)");
db.execSQL("INSERT INTO "+Geo_Create_Table +" VALUES (" +lat +"," +lon +","+1+")");
You should not be using execSQL, rather the insert method.
Your request should include '?', and the values should be added as parameters
Are you sure the lat and lon are integers?
The proper way to declare an Integer column in sqlite is NUMERIC
You should let sqlite handle the ID part itself
Also, if you run CREATE TABLE twice, it will crash. Run CREATE TABLE IF NOT EXISTS if you must.
What is the exception you get exactly?
精彩评论