我想将现有的SQLite数据库插入到我的Android项目中。
换句话说,我不想创建它,只是为了能够在我的应用程序中访问它。
我如何能够访问数据库,以及我应该在哪个文件夹中添加它?
答案 0 :(得分:1)
嗯,这很简单,只需将您的database.db放在assets文件夹中,您就可以使用Android SQLiteAssetHelper来读写数据库,这个库使这个过程变得非常简单和直接。
导入库
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
然后
public class MyDatabase extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "northwind.db";
private static final int DATABASE_VERSION = 1;
public MyDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
您只需要访问数据库即可。
Here就是您方便的完整示例。
答案 1 :(得分:0)
答案 2 :(得分:0)
将您的数据库放入资产文件夹
<asp:GridView runat="server" ID="gvForm"
CssClass="table table-striped table-bordered table-hover"
AllowPaging="True" AllowSorting="True"
PageSize="10"
OnPageIndexChanging="gvForm_PageIndexChanging"
OnRowEditing="gvForm_RowEditing"
OnRowCancelingEdit="gvForm_RowCancelingEdit"
OnRowUpdating="GridView_Main_RowUpdating"
OnRowDataBound="GridView_Main_RowDataBound">
<HeaderStyle CssClass="gridviewheader" HorizontalAlign="Left" VerticalAlign="Middle" />
<SelectedRowStyle CssClass="gridviewrowselected" BackColor="#e7e7e7" />
<PagerStyle BorderWidth="0" BackColor="#cccccc" />
<Columns>
<asp:TemplateField HeaderText="Action" Visible="true">
<ItemTemplate>
<asp:LinkButton ID="LnkEdit" CommandName="Edit" runat="server">
<i class="ace-icon fa fa-pencil-square-o bigger-13" title="Edit"></i>
<span class="sr-only">Edit</span>
</asp:LinkButton>
<asp:LinkButton ID="LnkUpdate" CommandName="Update" runat="server">
<i class="ace-icon fa fa-save bigger-13" title="Save"></i>
<span class="sr-only">Save</span>
</asp:LinkButton>
<asp:LinkButton ID="LnkCancel" CommandName="Cancel" runat="server">
<i class="ace-icon fa fa-ban bigger-13" title="Cancel"></i>
<span class="sr-only">Cancel</span>
</asp:LinkButton>
<asp:Label ID="lblWarning" runat="server">
<i class="ace-icon fa fa-warning bigger-13"
title="Waiting For Approval"></i>
<span class="sr-only">Waiting For Approval</span>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<div class="alert alert-block" style="margin: 8px 8px 8px 0">
<h4>Information</h4>
<p style="margin: 8px 0">
Data is not found.
</p>
</div>
</EmptyDataTemplate>
<PagerStyle CssClass="pagination-ys" />
</asp:GridView>