<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" > <Button
android:id="@+id/create_database"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="创建数据库"
android:layout_marginTop="10dp"
/>
</LinearLayout>

package com.example.databasetest;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast; /**
* Created by Administrator on 2016/3/4.
*/
public class DatabaseHelper extends SQLiteOpenHelper{ public static final String CREATE_BOOK = "create table book(id integer primary key autoincrement, author text,price real,pages integer,name text)";
private Context mContext; @Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_BOOK);
Toast.makeText(mContext,"创建数据库成功",Toast.LENGTH_SHORT).show();
} @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } public DatabaseHelper(Context context, String name, CursorFactory factory, int version) {
super(context, name, factory, version);
mContext = context;
}
}
package com.example.datebasetest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button; public class MainActivity extends AppCompatActivity { private Button btn;
private DatabaseHelper dbHelper; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); btn = (Button)findViewById(R.id.create_database);
dbHelper = new DatabaseHelper(this,"BookStore",null,1); btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dbHelper.getWritableDatabase();
}
});
}
}
												

Android 数据库管理— — —创建数据库的更多相关文章

  1. 利用SQLite在android上创建数据库

    利用SQLite在android上创建数据库 方法: 1.创建我们的数据库类继承SQLiteOpenHelper类 完成相关函数的重写和数据库对象的初始化 public MySQLiteOpenHel ...

  2. android: SQLite创建数据库

    SQLite 是一款轻量级的关系型数据库,它的运算速度非常快, 占用资源很少,通常只需要几百 K 的内存就足够了,因而特别适合在移动设备上使用.SQLite 不仅支持标准的 SQL 语法,还遵循了数据 ...

  3. Android 数据库管理— — —升级数据库

    package com.example.databasetest; import android.content.Context;import android.database.sqlite.SQLi ...

  4. Android——SQLite数据库(一)创建数据库、创建表、初始化数据

    xml <Button android:layout_width="match_parent" android:layout_height="wrap_conten ...

  5. Android 数据库管理— — —更新数据

    <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" ...

  6. Android 数据库管理— — —添加数据

    <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" ...

  7. 21.Android之SQLite数据库学习

    Google为Andriod的较大的数据处理提供了SQLite,他在数据存储.管理.维护等各方面都相当出色,功能也非常的强大.SQLite具备下列特点: 1.轻量级 使用 SQLite 只需要带一个动 ...

  8. Android基础------SQLite数据库(一)

    1.SQLite介绍 SQLite是一款非常流行的嵌入式数据库,它支持SQL操作,并且只用很少的内存. Android在运行时集成了SQLite,所有每个Android应用程序都可以使用SQLLite ...

  9. Android学习---如何创建数据库,SQLite(onCreate,onUpgrade方法)和SQLiteStudio的使用

    一.android中使用什么数据库? SQLite是遵守ACID的关系数据库管理系统,它包含在一个相对小的C程式庫中.它是D.RichardHipp建立的公有领域项目.SQLite 是一个软件库,实现 ...

随机推荐

  1. css样式之 direction

    今天看到 direction:rtl.一时有点发傻. 其实就是文本读取顺序.默认是ltr从左向右读.rtl是从右向左读取.

  2. C4.5,CART,randomforest的实践

    #################################Weka-J48(C4.5)################################# ################### ...

  3. SPSS数据分析—对数线性模型

    我们之前讲Logistic回归模型的时候说过,分类数据在使用卡方检验的时候,当分类过多或者每个类别的水平数过多时,单元格会划分的非常细,有可能会导致大量单元格频数很小甚至为0,并且卡方检验虽然可以分析 ...

  4. JavaScript模块化

    1.commonjs 导入: var math = require('math'); math.add(2,3); // 5 导出: module.exports={} 应用会停止并等待加载 2.AM ...

  5. discuz被别人评论一段代码,然后页面就变样了

                ۣۣۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖ ...

  6. Application.Run()和Form.Show()以及Form.ShowDialog()

    ShowDialog()弹出模式化的窗体 Show()弹出非模式化的窗体 模式窗体,在关闭或隐藏前无法切换到主窗体. 非模式窗体,变换焦点使不必关闭窗体 总结:显示重要的信息,还是用模式窗体,如删除文 ...

  7. IIS部署WCF网站服务步骤

    一开始在“管理工具”下找不到IIS的快捷方式,是因为系统默认未打开IIS功能,所以首先打开IIS功能: 为避免出现未知的麻烦,建议将IIS下的所有项都勾上: 创建IIS桌面快捷方式: 添加网站托管: ...

  8. LTE Air interface Channels-----http://www.rfwireless-world.com/Tutorials/LTE-logical-transport-physical-channels.html

    LTE technology works based on three channel types viz. logical channel,transport channel and physica ...

  9. CocoaPods安装流程

    iOS 最新版 CocoaPods 的安装流程       1.移除现有Ruby默认源 $gem sources --remove https://rubygems.org/   2.使用新的源 $g ...

  10. cacti web页面访问 settings出错

    查看apache错误日志: 错误信息Mon Dec 26 11:00:48.241653 2016] [:error] [pid 32607] [client 192.168.10.79:65009] ...