android sqlite 数据库的创建

[java]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. package com.itheima.db;  
  2.   
  3. import android.content.Context;  
  4. import android.database.sqlite.SQLiteDatabase;  
  5. import android.database.sqlite.SQLiteOpenHelper;  
  6.   
  7. public class PersonSQLiteOpenHelper extends SQLiteOpenHelper {  
  8.     /** 
  9.      * 数据库的构造方法 用来定义数据库的名称 数据库查询的结果集 数据库的版本 
  10.      * @param context 
  11.      */  
  12.     public PersonSQLiteOpenHelper(Context context) {  
  13.         super(context, "person.db",null,1);//1 必须是大于等于1的  
  14.     }  
  15.     /** 
  16.      * 数据库第一次创建的时候调用的方法 
  17.      * db 被创建的数据库 
  18.      */  
  19.     @Override  
  20.     public void onCreate(SQLiteDatabase db) {  
  21.         //初始化数据库的表结构  
  22.         String sql = " create table person (id integer primary key autoincrement,name varchar(50),number varchar(20))";  
  23.         db.execSQL(sql);  
  24.     }  
  25.   
  26.     @Override  
  27.     public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {  
  28.       
  29.     }  
  30.   
  31. }  

[java]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. package com.itheima.test;  
  2.   
  3. import com.itheima.db.PersonSQLiteOpenHelper;  
  4.   
  5. import android.test.AndroidTestCase;  
  6.   
  7. public class TestPersonDb extends AndroidTestCase {  
  8.     public void testCreateDb(){  
  9.         PersonSQLiteOpenHelper helper = new PersonSQLiteOpenHelper(getContext());  
  10.         helper.getWritableDatabase();  
  11.     }  
  12. }  

[html]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="com.itheima.db"  
  4.     android:versionCode="1"  
  5.     android:versionName="1.0" >  
  6.       
  7.     <instrumentation   
  8.         android:name="android.test.InstrumentationTestRunner"  
  9.         android:targetPackage="com.itheima.db"  
  10.         ></instrumentation>  
  11.     <uses-sdk  
  12.         android:minSdkVersion="8"  
  13.         android:targetSdkVersion="17" />  
  14.   
  15.     <application  
  16.         android:allowBackup="true"  
  17.         android:icon="@drawable/ic_launcher"  
  18.         android:label="@string/app_name"  
  19.         android:theme="@style/AppTheme" >  
  20.           
  21.         <uses-library android:name="android.test.runner"/>  
  22.         <activity  
  23.             android:name="com.itheima.db.MainActivity"  
  24.             android:label="@string/app_name" >  
  25.             <intent-filter>  
  26.                 <action android:name="android.intent.action.MAIN" />  
  27.   
  28.                 <category android:name="android.intent.category.LAUNCHER" />  
  29.             </intent-filter>  
  30.         </activity>  
  31.     </application>  
  32.   
  33. </manifest>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值