基于Android的SQLite数据库浏览器

基于Android的SQLite数据库浏览器,android,sqlite,Android,Sqlite,对于SQLiteDatabase可以接受哪些文件格式,我感到困惑。我想使用我在SQLite数据库浏览器中创建的现有数据库。有到SQL、CSV和文本文件的导出选项。我尝试在Notepad++中以文本文件和SQL文件的形式打开该文件,我看到的只是一个带有插入的CREATETABLE命令(通过SQLite数据库浏览器创建)这是错误的文件类型吗?还是SQLiteDatabase实际使用了这些信息来创建表?我将这些文件与自2009年以来被引用的代码一起使用:但该链接上的代码对我不起作用。无法打开该文件进行

对于SQLiteDatabase可以接受哪些文件格式,我感到困惑。我想使用我在SQLite数据库浏览器中创建的现有数据库。有到SQL、CSV和文本文件的导出选项。我尝试在Notepad++中以文本文件和SQL文件的形式打开该文件,我看到的只是一个带有插入的CREATETABLE命令(通过SQLite数据库浏览器创建)这是错误的文件类型吗?还是SQLiteDatabase实际使用了这些信息来创建表?我将这些文件与自2009年以来被引用的代码一起使用:但该链接上的代码对我不起作用。无法打开该文件进行复制,或者可以打开该文件,但一旦尝试查询,我会收到一个错误,提示“table name”找不到这样的表

代码:

顺便说一句,这是我的数据库文件的内容

BEGIN TRANSACTION;
CREATE TABLE ExtraInfo (commonName , hours , fare , website , summary );
INSERT INTO ExtraInfo VALUES('Alki Beach Park','4 am - 11:30 pm',-1,-1,'Enjoy the Seattle skyline, ride bikes, or fly kites at Alki Beach.');
INSERT INTO ExtraInfo VALUES('Bradner Gardens','4 am - 11:30 pm',-1,-1,'A 1.6-acre park in the Mt. Baker neighborhood of southeast Seattle. Enjoy a garden, p-patch, basketball court and more.');
INSERT INTO ExtraInfo VALUES('Experience Music Project','Hours vary by season. See website for details.','Range by age: $14 - $20',-1,'Experience music hands on! Explore music history and get creative in the interactive Sound Lab.');
INSERT INTO ExtraInfo VALUES('Japanese Garden','Hours vary by season. See website.','Varies. See website.','http://www.seattle.gov/parks/parkspaces/japanesegarden.htm','Located within the Washington Park Arboretum, this is a 3.5 acre formal garden designed and constructed under the supervision of world-renowned Japanese garden designer Juki Iida in 1960.');
INSERT INTO ExtraInfo VALUES('Katie Blacks Garden','4 am - 11:30 pm',-1,-1,'This historic landscape was originally created for Katie Black, an early Seattle settler. The community rallied to preserve it and has worked hard to remove blackberries and restore the garden.');
INSERT INTO ExtraInfo VALUES('Kubota Garden','6 am - 10 pm',-1,-1,'Hidden in South Seattle, Kubota Garden is a stunning 20 acre landscape that blends Japanese garden concepts with native Northwest plants.');
INSERT INTO ExtraInfo VALUES('Museum Of Flight','Daily 10 am - 5 pm.\nClosed Thanksgiving and Christmas.','Adults $17\nSeniors (65+) $14\nYouth(5-17) $9\nChildren (4 and under) Free','http://www.museumofflight.org/','A museum dedicated to the history of air and space flight. Collection includes 150+ historically significant air- and spacecraft.');
INSERT INTO ExtraInfo VALUES('Pacific Science Center','Daily 9:45 am - 6 pm','Exhibits Admission\nAdults(16-64) $16\nSeniors(65+) $14\nYouth(6-15) $11\nKids(3-5) $9',-1,'Explore science hands on through a variety of different exhibits such as "Dinosaurs: A Journey Through Time" or the "Science Playground".');
INSERT INTO ExtraInfo VALUES('Parsons Garden','6 am - 10 pm',-1,-1,'Formerly the family garden of Reginald H. Parsons, the park was given to the City in 1956 by the family''s children. Often used for ceremonies, this mall but lovely garden is a hidden gem on Queen Anne''s south slope.');
INSERT INTO ExtraInfo VALUES('Science Fiction Museum','Hours vary by season. See website for details.','Range by age: $14 - $20',-1,'Explore science fiction through film and literature at the Science Fiction Museum. Browse the exhibits'' large collection of film and TV props and memorabilia, as well as books.');
INSERT INTO ExtraInfo VALUES('Seattle Aquarium','Daily 9:30 am - 5 pm\nThanksgiving and Christmas Day 9:30 am - 3 pm\nChristmas Day Closed','Adults (13+) $19.95\nYouth(4-12) $13.95\nChild(3  & under) Free','http://www.seattleaquarium.org/','Come see a variety of cute and strange aquatic creatures!');
INSERT INTO ExtraInfo VALUES('Seattle Childrens Theatre',-1,-1,-1,'Seattle Children''s Theatre provides children of all ages access to professional theatre, with a focus on new works, and theatre education.');
INSERT INTO ExtraInfo VALUES('Volunteer Park Conservatory','6 am - 10 pm',-1,-1,'Located in the heart of Seattle, Volunteer Park is home to the Volunteer Park Conservatory, Seattle Asian Art Museum, Puget Sound and downtown views, and more.');
INSERT INTO ExtraInfo VALUES('Washington Park Arboretum','Dawn to Dusk',-1,-1,'Managed by the UW and City of Seattle, this 230 acre arboretum has a dynamic assortment of plants found nowhere else.');
INSERT INTO ExtraInfo VALUES('Woodland Park Zoo Rose Garden','4 am - 11:30 pm',-1,-1,'A multipurpose park and recreation space southwest of Green Lake and north of the Fremont district. Ideal for picnics (reservable), BBQs, sports and recreation.');
COMMIT;

这就是我询问文件格式的原因。我以前打开过其他sql、sqlite文件,但得到的是二进制乱码。我这里有一个简单的CREATE TABLE命令。

它不起作用,可能您没有在清单文件中授予权限。我想那篇教程没有提到这一点。将此添加到清单文件:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

您需要创建一个db类+db助手类

为什么?? 出于开发目的,您可以在emelutor内使用db,但在设备(如果不是根设备)上,您无法访问数据/数据文件夹

只需创建一个助手类。然后,它将创建您的数据库,在更新时对其进行管理等

4更多信息:


编辑:支持任何文件类型,因为linux使用魔法字节来确定文件类型…当您从SQLite浏览器保存数据库时,请将其保存为name.db或只是name(不是sql转储)

我对两件事做了更改。使用SQLite.openDatabase(…)的CREATE_IF_required标志,我意识到我使用了错误的文件格式。在使用数据库浏览器时,我将导出到SQL或TXT,而不是使用保存的文件。

Yaqub,我无法告诉您我已经阅读了多少次该文章或链接到它。一点帮助都没有。我特别问的是文件格式。你能发布你的代码并告诉我们错误发生在哪里吗?发布。在新安装时,我的数据库助手类检查db文件是否存在。如果没有,它将通过调用getReadableDatabase()创建一个数据库,然后将资产文件夹中的数据库复制到存储上的数据库。但是,当您尝试在复制后打开它时,它会说它不存在,即使DDMS显示它存在。请确保代码中引用的DB名称必须与资产文件夹中的DB名称相同。DB_NAME这里是数据库的名称。假设您在assets文件夹中有一个数据库副本,例如,如果您的数据库名为ordersDB,那么DB_name的值将为ordersDB,我回答这是一个错误的方法,因为每次安装都需要创建DB
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>