When I try to query using my db in the femulator it works perfectly, but given the same appliction and same varibales into the device (milestone) it seems like the DB is not recognized.
I think the key to solving it is to understand where on the device we store the db.
On the emulator it's on /data/data/com.countryCityGame/databases/test1.db
But when I am using the device itself 开发者_如何转开发it must be in another place, does someone know where?
This is the java code where I build the DB:
public static void main(String[] args) throws Exception {
String CITIES[] = city.split(",");
String ANIMEL[] = animel.split(",");
String CELEB[] = UK_CELEB.split(",");
String Nature[] = vegtablesAndFruiets.split(",");
String V[][] = {COUNTRIES,CITIES,ANIMEL,Nature,occupations,CELEB};
String []TypeNames = {"Country","City","Animels","Nature","Occupation","Celeb"};
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:test1.db");
Statement stat = conn.createStatement();
//stat.executeUpdate("drop table if exists "+"android_metadata"+";");
stat.executeUpdate("create table android_metadata (\"locale\" TEXT DEFAULT 'en_US');");
//PreparedStatement prep1 = conn.prepareStatement(
// "insert into "+"android_metadata"+" values (?);");
//prep1.setString(1, "en_US") ;
//prep1.addBatch();
stat.executeUpdate("drop table if exists "+TABLE_NAME+";");
//stat.executeUpdate("create table "+TABLE_NAME+" (name, occupation);");
stat.executeUpdate("create table "+TABLE_NAME+" ("+VALUE+" TEXT NOT NULL,"+TYPE+" TEXT NOT NULL,"+LETTER+" TEXT NOT NULL,"+counter+" INTEGER);");
PreparedStatement prep = conn.prepareStatement(
"insert into "+TABLE_NAME+" values (?,?,?,?);");
//private void insertToTalble();
int j=0,i=0;
try{
for(j = 0 ;j < V.length; j++)
for (i = 0 ;i < V[j].length ; i++)
{
if (V[j][i] != null)
{
V[j][i] = asUpperCaseFirstChar(V[j][i]);
Character c = V[j][i].charAt(0);
prep.setString(3, c.toString());
}
prep.setString(1, V[j][i]);
prep.setString(2, TypeNames[j]);
prep.setInt(4,0);
prep.addBatch();
}
}catch(Exception e) {
System.out.println("***********"+i+"***************");
}
conn.setAutoCommit(false);
prep.executeBatch();
// prep1.executeBatch();
conn.setAutoCommit(true);
ResultSet rs = stat.executeQuery("select * from "+TABLE_NAME+";");
while (rs.next()) {
System.out.println("country name = " + rs.getString(VALUE));
System.out.println("type = " + rs.getString(TYPE));
System.out.println("letter = " + rs.getString(LETTER));
System.out.println("********************************");
}
rs.close();
conn.close();
}
and this is the code from where i first get the bug:
private static final String DB_PATH = "/data/data/com.countryCityGame/databases/test1.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) {
points = 0;//init values
Cursor cursor = null ;
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{
db = SQLiteDatabase.openDatabase(DB_PATH , null, SQLiteDatabase.NO_LOCALIZED_COLLATORS/*SQLiteDatabase.CREATE_IF_NECESSARY*/);
//this question
cursor = db.query(TABLE_NAME, new String[] {LETTER}
,LETTER+ " like " + "'%" + "A" +"%'", null, null, null, null);
if ( !cursor.moveToFirst()){
//*****if data base doesnot exist HERE I GOT PROBLEMES****
this.db = openHelper.getWritableDatabase();//make new data base
}
}catch(SQLiteException e){
this.db = openHelper.getWritableDatabase();//make new data base
// for (int i = 0 ; i < ALLVALUES.length ; i++)
// insertValus(ALLVALUES[i],i);
}
NOTICE: In the device I am using /data/data/com.countryCityGame/databases/test1.db
, it might not be the path where the appliction is located onto the device I am using.
精彩评论