Tuesday, 20 August 2013

Android SQLite Database Conection Error

Android SQLite Database Conection Error

I want to Connect my App with a Database on the Android Phone, so I've
written a Class called DBHelper.
But I get An Error, wich Says "MODE_PRIVATE" connot be resolved to a
variable. So i made "Context.MODE_PRIVATE". Now, the Variable can be
resolved, but I get a new Error: "The method openOrCreateDatabase(String,
int, null) is undefinded for the Type DBHelper". It dont helps if I use
DBHelper.this.openOrCreateDatabase to open it.
Can anybody help me?
This is my Code:
public class DBHelper {
SQLiteDatabase db;
public void insert(String news, Context con){
db = openOrCreateDatabase("PlanB", con.MODE_PRIVATE, null);
db.execSQL("DROP TABLE IF EXISTS News");
db.execSQL("CREATE TABLE IF NOT EXISTS INBOX(id INTEGER,title
VARCHAR,text VARCHAR,date VARCHAR);");
String[] divided = news.split("/newentry/");
int length = divided.length;
int pos = 0;
while(pos <= length){
String[] entry = divided[pos].split("/;/");
db.execSQL("INSERT INTO INBOX
VALUES('"+entry[0]+"','"+entry[1]+"','"+entry[2]+"','"+entry[3]+"');");
pos++;
}
db.close();
}
}

No comments:

Post a Comment