views:

52

answers:

1

I am making an sqlight using eclipse outside the android project

what should I add into my android manifest in order to make it work ?

thank you Mathias, lets take this q to another project who genrate a sql file using java assuming this how can I set the

  SQLiteDatabase.NO_LOCALIZED_COLLATORS

flag when calling

  SQLiteDatabase.openDatabase()?

my code over there is

Class.forName("org.sqlite.JDBC");            
Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");
/*
*some code 
*/
   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 (?, ?,?);");

even when i use:

  db = SQLiteDatabase.openDatabase(myPath, null,  SQLiteDatabase.NO_LOCALIZED_COLLATORS);

when I use the query :

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

I get an exception .

A: 

You don't need to add anything special into the android manifest. You can open the database from anywhere, i.e. also from your sdcard or else. Otherwise, A common place to put the database is in to the assets folder of your application.

When you create the db outside the android project, just make sure you either create the metadata table (as mentioned in the Android docs) or set the SQLiteDatabase.NO_LOCALIZED_COLLATORS flag when calling SQLiteDatabase.openDatabase(). Also you should note that the primary key in all tables is _id. These are the most important things to consider when creating a new DB.

Also helpful regarding the metadata-table might be:

http://stackoverflow.com/questions/3061868/what-is-the-android-metadata-table

http://stackoverflow.com/questions/2528489/no-such-table-android-metadata-whats-the-problem

Helpful blog: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

Mathias Lin
where should i had the SQLiteDatabase.NO_LOCALIZED_COLLATORS flag when calling SQLiteDatabase.openDatabase() ?
yoav.str
see http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.htmlAs the third parameter of the openDatabase(String, SQLiteDatabase.CursorFactory, int) method. You call this in you application where you're open the database.
Mathias Lin
another q when i am using the emulator and want to take local application files i.e our database i am using :private static final String DB_PATH = "/data/data/com.myappname/assets/test1.db"; is that the right place on the emulator?
yoav.str
I think the path would "/data/data/com.myappname/databases/test1.db". You can actually browse the emulator via ddms in Eclipse (or also standalone, ddms is a tool in the Android SDK). Then you will have a tab 'File Explorer' where you can browse the system and also the data folder.
Mathias Lin