Android Open Source - test-gradle My Database Helper






From Project

Back to project page test-gradle.

License

The source code is released under:

Copyright (c) <2013> <Paul Estrada> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the S...

If you think the Android project test-gradle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.listexample.sql;
/*from  w  w  w . ja v a  2 s. c o  m*/
import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class MyDatabaseHelper {
  
  MySqliteHelper helper = null;
  SQLiteDatabase db = null;
  
  public MyDatabaseHelper(Context context) {
    helper = new MySqliteHelper(context);
    db = helper.getWritableDatabase();
  }
  
  public long insertUser(String name, String phone) {
    ContentValues contentValues = new ContentValues();
    contentValues.put(DBConstants.COLUMN_USER_NAME, name);
    contentValues.put(DBConstants.COLUMN_USER_PHONE, phone);
    
    return db.insert(DBConstants.TABLE_NAME_USERS, null, contentValues);
  }
  
  public int updatetUser(int id, String name, String phone) {
    ContentValues contentValues = new ContentValues();
    contentValues.put(DBConstants.COLUMN_USER_NAME, name);
    contentValues.put(DBConstants.COLUMN_USER_PHONE, phone);
    String whereClause = DBConstants.COLUMN_USER_ID + "=?";
    return db.update(DBConstants.TABLE_NAME_USERS, contentValues, whereClause, new String[]{id+""});
  }
  
  public List<User> selectUsers(String where) {
    List<User> users = new ArrayList<User>();
    try {
      Cursor cursor = db.query(DBConstants.TABLE_NAME_USERS, null, where, null, null, null, null);
      User user = null;
      if (cursor != null){
        if (cursor.moveToFirst()) {
          do {
            user = new User();
            user.setId(cursor.getInt(cursor.getColumnIndex(DBConstants.COLUMN_USER_ID)));
            user.setName(cursor.getString(cursor.getColumnIndex(DBConstants.COLUMN_USER_NAME)));
            user.setPhone(cursor.getString(cursor.getColumnIndex(DBConstants.COLUMN_USER_PHONE)));
          } while(cursor.moveToNext());
        }
      }
    } catch (Exception e) {
    }
    return users;
  }
  
  public void close() {
    db.close();
  }

}




Java Source Code List

com.example.listexample.GpsActivity.java
com.example.listexample.MainActivity.java
com.example.listexample.MultiListActivity.java
com.example.listexample.MyAdapter.java
com.example.listexample.NavigationAActivity.java
com.example.listexample.NavigationBActivity.java
com.example.listexample.ViewHolderRB.java
com.example.listexample.ViewHolderTV.java
com.example.listexample.ViewHolder.java
com.example.listexample.sql.DBConstants.java
com.example.listexample.sql.MyDatabaseHelper.java
com.example.listexample.sql.MySqliteHelper.java
com.example.listexample.sql.SqliteActivity.java
com.example.listexample.sql.User.java
com.example.listexample.utils.GetTweetsTask.java
com.example.listexample.utils.HttpUtils.java
com.example.listexample.utils.JsonParser.java
com.example.listexample.utils.Tweet.java
com.example.listexample.webapp.MyWebAppActivity.java
com.example.listexample.webapp.MyWebViewClient.java
com.example.listexample.webapp.WebViewBridge.java