Cannot create SQL database from downloaded file which is saved in /data/data/appname/files-Collection of common programming errors
I tried searching all around but cannot find a definite solution.
What I trying to do is to download an always updated with new inputs SQL file in XML format from URL and save it in the /data/data/appprogram/files/ folder. The downloading of file is completed and tested confirmed file is downloaded into emulator through DDMS file explorer.
Next I want to open this file to get all the statements and parse it into a database defined as camera_database which is located in /data/data/appprogram/databases. This is where the problem begins. I cannot get beyond this point.
I tried to input the data using both inputstream and openfileinput but not working.
Below is the code I used. Please advise from any kind soul..
public class Help_DatabaseHelperAdv extends SQLiteOpenHelper {
public static final String CAMERA_DATABASE_NAME = "camera_database";
protected Context camera_context;
public Help_DatabaseHelperAdv(Context context) {
super(context, CAMERA_DATABASE_NAME, null, 1);
this.camera_context = context;
}
@Override
public void onCreate(SQLiteDatabase cameradb) {
String s;
try {
InputStream in = camera_context.getApplicationContext().openFileInput("/data/data/appprogram/files/alladvertlist.xml");
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in, null);
NodeList statements = doc.getElementsByTagName("statement");
for (int i=0; i 0 ) {
//add the data in the buffer to the file in the file output stream (the file on the sd card
fileOutput.write(buffer, 0, bufferLength);
//add up the size so we know how much is downloaded
downloadedSize += bufferLength;
//Here we update the progress
progress = downloadedSize;
myProgress.setProgress(progress);
}
//close the output stream when done
fileOutput.close();
myProgress.dismiss();
//catch some possible errors...
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
i tried searching has it to do with byte or string when i do inputstream to documentbuilder but seems like it is not really the cause. below is the structure of SQL file downloadable from url, eliminating the contents
....
05-15 01:51:13.347: E/SQLiteLog(1391): (1) no such table: alladvert
05-15 01:51:13.347: D/AndroidRuntime(1391): Shutting down VM
05-15 01:51:13.347: W/dalvikvm(1391): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
05-15 01:51:13.377: E/AndroidRuntime(1391): FATAL EXCEPTION: main
05-15 01:51:13.377: E/AndroidRuntime(1391): java.lang.RuntimeException: Unable to start activity ComponentInfo{advertisebiz.gadgetscan/advertisebiz.gadgetscan.AdvPage02}: android.database.sqlite.SQLiteException: no such table: alladvert (code 1): , while compiling: SELECT _id, advcategory FROM alladvert WHERE advcategory = ?