I'm trying to create a database from an outer class tht my main Activity. The problem is that I always got that my database is invalid, and so I can't work on it.
I built a stand-alone class, with (at the moment) just 3 methods, one for creating the db, one for creating the (only) table, and another one for inserting data into it.
But, as I said, I can't create the db. I looked too in the emulator filesystem, and in fact there's no db under my package.
Where I'm wrong?
Using java Syntax Highlighting
- package com.google.android.tvfinder.db;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteDatabase.CursorFactory;
- import android.util.Log;
- public class DBHandler {
- private static final int DATABASE_VERSION = 1;
- private final String MY_DATABASE = "TvDb.db";
- private static final String MY_TABLE = "t_programs";
- private CursorFactory c = null;
- SQLiteDatabase myDB = null;
- public void createDatabase() {
- try {
- /* Create the Database (no Errors if it already exists) */
- Log.v("CREATING DATABASE","HELLO!!!!");
- myDB = SQLiteDatabase.create(MY_DATABASE, DATABASE_VERSION, c);
- } catch (Exception e) {}
- /* Open the DB and remember it */
- myDB = SQLiteDatabase.open(MY_DATABASE, c);
- }
- public void createTable() {
- createDatabase();
- /* Create a Table in the Database. */
- myDB.execSQL("CREATE TABLE IF NOT EXISTS "
- + MY_TABLE
- + " (Title VARCHAR, "
- + " Channel VARCHAR "
- + " Date VARCHAR "
- + " Genre VARCHAR, "
- + " Description VARCHAR "
- + " Start VARCHAR );");
- }
- public void insertProgram(String Title, String Channel, String Date, String Genre,
- String Description, String Start) {
- myDB.execSQL("INSERT INTO " + MY_TABLE + " " + Title + "," + Channel + "," + Date + "," + Genre
- + "," + Description + "," + Start +")");
- }
- public Cursor queryByTitle(String titleToQuery) {
- return myDB.query(false, MY_TABLE, null, " Title like '%" + titleToQuery + "%'", null, null, null, null);
- }
- public void closeDb() {
- if (myDB != null)
- myDB.close();
- }
- }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4



