我如何通过从SQL文件导入创建Android的SQLite数据库? [英] How do I create an SQLite database in Android by importing from an SQL file?

查看:390
本文介绍了我如何通过从SQL文件导入创建Android的SQLite数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含SQL很大的文本文件 CREATE TABLE 插入语句。如何导入在 SQLiteOpenHelper 的onCreate 方法,此文件?

I have a big text file containing SQL CREATE TABLE and INSERT statements. How do I import this file in the SQLiteOpenHelper onCreate method?

或者,有没有直接使用二进制数据库文件的接受的方式?

Or, is there an accepted way of using the binary database file directly?

我需要这与Android 1.6兼容。

I need this to be compatible with Android 1.6.

推荐答案

在SQLiteOpenHelper onCreate()方法可以只使用 db.execSQL(...),但这取决于你如何文本文件的结构(以及有多大它是)。

In the SQLiteOpenHelper onCreate() method you can just use db.execSQL(...) but that depends on how your 'text file' is structured (and how big it is).

另外,你可以'船'一个SQLite数据库与您的应用程序 - 看到这个链接给你的一些想法......

Alternatively, you can 'ship' a SQLite db with your app - see this link to give you some ideas...

使用Android中你自己的SQLite数据库应用

这篇关于我如何通过从SQL文件导入创建Android的SQLite数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆