views:

94

answers:

1

I have made db using java this way :

public static void main(String[] args) throws Exception {
      String CITIES[] = city.split(",");
      Class.forName("org.sqlite.JDBC");
        Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");

       String V[][] = {COUNTRIES,CITIES,occupations}; 
       String []TypeNames = {"country","city","occupation"};
        Statement stat = conn.createStatement();
    stat.executeUpdate("drop table if exists "+TABLE_NAME+";");
    //stat.executeUpdate("create table "+TABLE_NAME+" (name, occupation);");
    stat.executeUpdate("create table "+TABLE_NAME+" ("+VALUE+","+TYPE+","+LETTER+");");
    PreparedStatement prep = conn.prepareStatement(
      "insert into "+TABLE_NAME+" values (?, ?,?);");

    //private void insertToTalble();
    for(int j = 0 ;j < V.length; j++)
        for (int i = 0 ;i < V[j].length ; i++)
        {
        Character c = V[j][i].charAt(0);
        prep.setString(1, V[j][i]+"\n");
        prep.setString(2, TypeNames[j]);
        prep.setString(3, c.toString());

        prep.addBatch();
        }

    conn.setAutoCommit(false);
    prep.executeBatch();
    conn.setAutoCommit(true);

    rs.close();
    conn.close();
  }
}

when i open it using sqllight data browser it works fine but after adding it to new diractory in my android project called databases/test1.db

I am having problems using it

my android class whom works with the data base is :

     private static final String DB_PATH = "/data/data/com.countryCityGame/databases/test.db";
    private static final String DATABASE_NAME = "test1.db";
    private static final int DATABASE_VERSION = 1;
    private static final String TABLE_NAME = "GameTable";
    private static final String VALUE = "value";
    private static final String TYPE = "type";
    private static final String LETTER = "letter";


    public countryCityGameLogic(EditText[] myEditTextArr , Context context){

        this.context = context;
        openHelper = new OpenHelper(context);
        gameList = new CharSequence [myEditTextArr.length];
        for (int i = 0 ; i < myEditTextArr.length; i++){
            gameList[i] = myEditTextArr[i].getText();
        }
        this.db = openHelper.getWritableDatabase();

        try{
            String myPath = DB_PATH ;
            SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

        }catch(SQLiteException e){

            //database does't exist yet.
            //insertValus(COUNTRIES,0);

        }
        //insertValus(COUNTRIES,0);
    }
    public void setGameVar(EditText[] myEditTextArr) {
        for (int i = 0 ; i < myEditTextArr.length ;i++)
        gameList[i] = myEditTextArr[i].getText();
    }
    private void insertValus(String []typeInserted , int num) {
        ContentValues initialValues = new ContentValues();
          for (int i = 0 ; i < typeInserted.length ; i++){
              Character tmp = (Character)typeInserted[i].charAt(0);
              initialValues.put(VALUE, typeInserted[i]);
              initialValues.put(TYPE, TYPESNAMES[num]);
              initialValues.put(LETTER,tmp.toString(tmp));

          db.insert(TABLE_NAME, null, initialValues);
          }
    }



    private static class OpenHelper extends SQLiteOpenHelper {

          OpenHelper(Context context) {
             super(context, DATABASE_NAME, null, DATABASE_VERSION);
          }

          @Override
          public void onCreate(SQLiteDatabase db) {
             db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " ( "+ VALUE +" TEXT,"+ TYPE +" TEXT, "+ LETTER + " TEXT)");
          }

          @Override
          public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
             db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
             onCreate(db);
          }
       }


    public boolean existInDataBase() {
        boolean returnval = true;


        String s = asUpperCaseFirstChar(gameList[0].toString());
        Cursor cursor = db.query(TABLE_NAME, new String[] {VALUE}
        ,VALUE+" like " + "'%" + s +"%'", null, null, null, null);

        if ( cursor.moveToFirst() == false)
            returnval = false;

        return returnval;
    }

i am not getting any information in the cursor in existInDataBase() function to be more specific I'm always getting false for cursor.moveToFirst() even when my query is just to select without any thing

can someone please : 1.tell me what he thinks is wrong 2.how can i debug and see what there is in the db (i debug but i cant see anything odd should i had a if saying "you have no data base")

note " when i builded the app the first time the app was the the one who build the db as you can see in

 private void insertValus(String []typeInserted , int num);

my problem seems to be the manifest file:

when one takes a db file and import it to his android project what should he do ?please explain in steps what should i do thanks yoav.

A: 

Did you read this tutorial?

To see what in your database on device use "adb shell" command. From adb shell you can connect to database using sqlite3 command. Additional info can be found here

Orsol
yes I did , the problem seems to b when i add database from java project to mine own problems accrue.the reason why i import a database is couse otherwise it takes long period of time (for dalvik to insert somthig like 6 MB into a db file every time the app is starting to work is a huge effort ).so i set goal to make one outside my project , it will also help me building later my app on google cloud .
yoav.str
So where is android_metadata?
Orsol
android_metadata? I am not familiar with changes I should do there can you please drill down on that topic it might b the joker card I have been searching for...
yoav.str
Your database must contains android_metadata table CREATE TABLE "android_metadata" ("locale" TEXT DEFAULT 'en_US')
Orsol
can you please show it in an anwser where everthing is explined ?1.where i should write "android_metadata" ("locale" TEXT DEFAULT 'en_US')2.when i add a db to my project what should i do just grap and drop to his eclipse directory or should i do more thnku so much i am having troubles with it for long time and no one i know knows somthing about this platform and by accomplishing that bug i think i will accomplish the app
yoav.str
All already explained here http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/If you will have additional question feel free to ask.
Orsol
Also see this thread:http://stackoverflow.com/questions/2528489/no-such-table-android-metadata-whats-the-problem
Mathias Lin