Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
针对android的sqlite查询_Android_Android Sqlite - Fatal编程技术网

针对android的sqlite查询

针对android的sqlite查询,android,android-sqlite,Android,Android Sqlite,我在android应用程序的Sqlite中定义了一个表,但我似乎不能定义多行。。 包my.first.pro import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import a

我在android应用程序的Sqlite中定义了一个表,但我似乎不能定义多行。。 包my.first.pro

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


public class DBAdapter {

public static final String KEY_NAME = "name";
public static final String KEY_EIGHTU = "8u";
public static final String KEY_NINEU = "9u";
public static final String KEY_TENU = "10u";
public static final String KEY_ELEVENU = "11u";

private static final String DB_NAME = "db_example";
private static final String DB_TABLE = "al amal";
private static final int    DB_VER = 1;

// a SQL statement to create a new table
private static final String DB_CREATE = 
    "CREATE TABLE al amal (name TEXT NOT NULL, 8u TEXT NOT NULL, 9u TEXT NOT NULL, 10u    TEXT NOT NULL, 11u TEXT NOT NULL);";


private static class DatabaseHelper extends SQLiteOpenHelper {

    // Class constructor
    DatabaseHelper(Context c) {
        super(c, DB_NAME, null, DB_VER);
    }

    // called by the parent class when a DB doesn't exist
    public void onCreate(SQLiteDatabase db) {
        // Execute our DB_CREATE statement
        db.execSQL(DB_CREATE);
    }


}


private final Context context;  
private DatabaseHelper helper;
private SQLiteDatabase db;

// DBAdapter class constructor
public DBAdapter(Context c) {
    this.context = c;
}


public DBAdapter open() throws SQLException {
    // instantiate a DatabaseHelper class (see above)
    helper = new DatabaseHelper(context);

            db = helper.getWritableDatabase();

    return this;
}


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


//String name, String eu, String nu, String tu, String elu
public long insertUser( ) {
    ContentValues vals = new ContentValues();

    //the following is filling the first row.. but i don't know how to fill out more than one row
    vals.put(KEY_NAME, "John Smith");
    vals.put(KEY_EIGHTU, "F");
    vals.put(KEY_NINEU, "F");
    vals.put(KEY_TENU, "NF");
    vals.put(KEY_ELEVENU, "NF");
    return db.insert(DB_TABLE, null, vals);
}



public void findavailabe (String name) {
// Perform a database query
Cursor cursor = db.query(
        DB_TABLE, // table to perform the query
        new String[] { KEY_NAME,KEY_EIGHTU,KEY_NINEU,KEY_TENU,KEY_ELEVENU }, //resultset columns/fields
        KEY_NAME+"=? AND "+KEY_EIGHTU+"=? AND"+KEY_NINEU+"=? AND "+KEY_TENU+"=? AND "+KEY_ELEVENU, //condition or selection
        new String[] { user, pass },  //selection arguments (fills in '?' above)
        null,  //groupBy
        null,  //having
        null   //orderBy
    );


/** Authenticate a user by querying the table to see
  * if that user and password exist. We expect only one row
  * to be returned if that combination exists, and if so, we
  * have successfully authenticated.
  * 
  * @param user username (string)
  * @param pass user's password (string)
  * @return true if authenticated, false otherwise
 */
/**public boolean authenticateUser(String user, String pass) {
    // Perform a database query
    Cursor cursor = db.query(
            DB_TABLE, // table to perform the query
            new String[] { KEY_USER }, //resultset columns/fields
            KEY_USER+"=? AND "+KEY_PASS+"=?", //condition or selection
            new String[] { user, pass },  //selection arguments (fills in '?' above)
            null,  //groupBy
            null,  //having
            null   //orderBy
        );

    // if a Cursor object was returned by the query and
    // that query returns exactly 1 row, then we've authenticated
    if(cursor != null && cursor.getCount() == 1) {
        return true;
    }

    // The query returned no results or the incorrect
    // number of rows
    return false;
}

}}

第二个问题:在sqlite中执行查询时遇到问题我的表由五列组成。。第一个是姓名,另外四个是预约时间。。我想免费搜索标记为“F”的可用约会的特定名称。

我似乎无法定义多行

您的函数
insertUser()
可以修改为传入定义行的5个值。然后,多次调用该函数将产生多行,例如:

public long insertUser(String name, String eightU, String nineU, String tenU, String elevanU) {
   ContentValues vals = new ContentValues();

   vals.put(KEY_NAME, name);
   vals.put(KEY_EIGHTU, eightU);
   vals.put(KEY_NINEU, nineU);
   vals.put(KEY_TENU, tenU);
   vals.put(KEY_ELEVENU, elevanU);
   return db.insert(DB_TABLE, null, vals);
}