当前位置:操作系统 > 安卓/Android >>

android数据库操作(一)

 

为了以后的项目使用Android数据库更方便,自已写了一个小的应用框架,不知道算不算称得上框架,反正自已用起来觉得还是挺方便的,参考Hibernate了应用思想。

 

业务介绍

 

1、建一个数据库madfiger.db

 

2、建一个用户表UserInfo,包含一些用户基本字段

 

 

 

好了那么我们现在来实现吧

 

 

 

1、新建UserInfo实体类,继承AbstractBaseModel,UserInfo的类名为数据库表名,字段分别为实现了Get与Set方式的实性字段;

 

 

 

UserInfo代码如下:

 

Java代码 

package cn.company.android.project.model;  

 

import java.util.Calendar;  

import java.util.Date;  

import java.util.Locale;  

  

import cn.madfinger.android.core.AbstractBaseModel;  

import cn.madfinger.android.core.util.DateUtils;  

 

public class UserInfo extends AbstractBaseModel{  

    private static final long serialVersionUID = -7079062473198239915L;  

    private String id;  

    private String username;  

    private String password;  

    private String birthday;  

    private int gender;  

    private float weight;  

    private Date createTime=DateUtils.long2Date(Calendar.getInstance(Locale.CHINESE).getTimeInMillis());  

    public UserInfo(){  

        super();  

    }  

    public String getId() {  

        return id;  

    }  

    public void setId(String id) {  

        this.id = id;  

    }  

    public String getUsername() {  

        return username;  

    }  

    public void setUsername(String username) {  

        this.username = username;  

    }  

    public String getPassword() {  

        return password;  

    }  

    public void setPassword(String password) {  

        this.password = password;  

    }  

    public String getBirthday() {  

        return birthday;  

    }  

    public void setBirthday(String birthday) {  

        this.birthday = birthday;  

    }  

    public int getGender() {  

        return gender;  

    }  

    public void setGender(int gender) {  

        this.gender = gender;  

    }  

    public float getWeight() {  

        return weight;  

    }  

    public void setWeight(float weight) {  

        this.weight = weight;  

    }  

    public Date getCreateTime() {  

        return createTime;  

    }  

    public void setCreateTime(Date createTime) {  

        this.createTime = createTime;  

    }  

 

package cn.company.android.project.model;

 

import java.util.Calendar;

import java.util.Date;

import java.util.Locale;

 

import cn.madfinger.android.core.AbstractBaseModel;

import cn.madfinger.android.core.util.DateUtils;

 

public class UserInfo extends AbstractBaseModel{

       private static final long serialVersionUID = -7079062473198239915L;

       private String id;

       private String username;

       private String password;

       private String birthday;

       private int gender;

       private float weight;

       private Date createTime=DateUtils.long2Date(Calendar.getInstance(Locale.CHINESE).getTimeInMillis());

       public UserInfo(){

              super();

       }

       public String getId() {

              return id;

       }

       public void setId(String id) {

              this.id = id;

       }

       public String getUsername() {

              return username;

       }

       public void setUsername(String username) {

              this.username = username;

       }

       public String getPassword() {

              return password;

       }

       public void setPassword(String password) {

              this.password = password;

       }

       public String getBirthday() {

              return birthday;

       }

       public void setBirthday(String birthday) {

              this.birthday = birthday;

       }

       public int getGen

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,