{"id":5459,"date":"2014-03-30T22:17:54","date_gmt":"2014-03-30T22:17:54","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/cannot-create-sql-database-from-downloaded-file-which-is-saved-in-data-data-appname-files-collection-of-common-programming-errors\/"},"modified":"2014-03-30T22:17:54","modified_gmt":"2014-03-30T22:17:54","slug":"cannot-create-sql-database-from-downloaded-file-which-is-saved-in-data-data-appname-files-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/cannot-create-sql-database-from-downloaded-file-which-is-saved-in-data-data-appname-files-collection-of-common-programming-errors\/","title":{"rendered":"Cannot create SQL database from downloaded file which is saved in \/data\/data\/appname\/files-Collection of common programming errors"},"content":{"rendered":"<p>I tried searching all around but cannot find a definite solution.<\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n<p>I tried to input the data using both inputstream and openfileinput but not working.<\/p>\n<p>Below is the code I used. Please advise from any kind soul..<\/p>\n<pre><code>public class Help_DatabaseHelperAdv extends SQLiteOpenHelper {\n\npublic static final String CAMERA_DATABASE_NAME = \"camera_database\";\n\nprotected Context camera_context;\n\npublic Help_DatabaseHelperAdv(Context context) {\n    super(context, CAMERA_DATABASE_NAME, null, 1);\n    this.camera_context = context;\n}\n\n@Override\npublic void onCreate(SQLiteDatabase cameradb) {\n    String s;\n    try {\n        InputStream in = camera_context.getApplicationContext().openFileInput(\"\/data\/data\/appprogram\/files\/alladvertlist.xml\");\n\n\n        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();\n        Document doc = builder.parse(in, null);\n        NodeList statements = doc.getElementsByTagName(\"statement\");\n        for (int i=0; i 0 ) {\n                \/\/add the data in the buffer to the file in the file output stream (the file on the sd card\n                fileOutput.write(buffer, 0, bufferLength);\n                \/\/add up the size so we know how much is downloaded\n                downloadedSize += bufferLength;\n                \/\/Here we update the progress\n                progress = downloadedSize;\n                myProgress.setProgress(progress);\n        } \n\n        \/\/close the output stream when done\n        fileOutput.close();\n        myProgress.dismiss();\n      \/\/catch some possible errors...\n    } catch (MalformedURLException e) {\n            e.printStackTrace();\n    } catch (IOException e) {\n            e.printStackTrace();\n    }\n        }\n    }).start(); \n\n}\n<\/code><\/pre>\n<p>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<\/p>\n<pre><code>\n .... \n\n\n05-15 01:51:13.347: E\/SQLiteLog(1391): (1) no such table: alladvert\n05-15 01:51:13.347: D\/AndroidRuntime(1391): Shutting down VM\n05-15 01:51:13.347: W\/dalvikvm(1391): threadid=1: thread exiting with uncaught exception (group=0x40a71930)\n05-15 01:51:13.377: E\/AndroidRuntime(1391): FATAL EXCEPTION: main\n05-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 = ?\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5459","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5459"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5459\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}