如何从android中的salesforce中创建的数据库中获取数据?

时间:2014-03-20 12:05:41

标签: android salesforce

我正在尝试从salesforce中创建的数据库中获取数据,之前我还没有处理过,也不知道如何访问该数据库。任何人都可以告诉我任何参考或任何想法,我怎么能实现这一点。

2 个答案:

答案 0 :(得分:0)

try this one..
package com.example.todoapp.sql;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHandler extends SQLiteOpenHelper {
    private static final int dbversion = 1;
    private static final String dbname = "todomanager";
    private static final String tabletodo = "todosamp";
    private static final String id = "id";
    private static final String name = "name";

    public DatabaseHandler(Context tododata) {
        super(tododata, dbname, null, dbversion);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "CREATE TABLE " + tabletodo + "(" + id
                + " INTEGER PRIMARY KEY," + name + " TEXT)";
        db.execSQL(sql);
        // db.execSQL("create table todosamp id integer primary key,name text");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        db.execSQL("DROP TABLE IF EXISTS " + tabletodo);

        onCreate(db);
    }
}

package com.example.todoapp.dao;

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;

import com.example.todoapp.data.todo;
import com.example.todoapp.sql.DatabaseHandler;

public class tododata {

    private SQLiteDatabase db;
    private DatabaseHandler dbHelper;

    public tododata(Context context) {
        dbHelper = new DatabaseHandler(context);
        db = dbHelper.getWritableDatabase();
    }

    public void close() {
        db.close();
    }

    public void createTodo(String todoText) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("name", todoText);
        db.insert("todosamp", null, contentValues);
    }

    public void deleteTodo(int todoId) {

        db.delete("todosamp", "id = " + todoId, null);
    }

    public List<todo> getTodos() {
        List<todo> todoList = new ArrayList<todo>();

        String[] tableColumns = new String[] { "id", "name" };

        Cursor cursor = db.query("todosamp", tableColumns, null, null, null,
                null, null);
        cursor.moveToFirst();

        while (!cursor.isAfterLast()) {
            todo t = new todo();
            t.setId(cursor.getInt(0));
            t.setText(cursor.getString(1));

            todoList.add(t);
            cursor.moveToNext();
        }

        return todoList;
    }

}

答案 1 :(得分:0)