Example usage for android.database.sqlite SQLiteDatabase execSQL

List of usage examples for android.database.sqlite SQLiteDatabase execSQL

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase execSQL.

Prototype

public void execSQL(String sql, Object[] bindArgs) throws SQLException 

Source Link

Document

Execute a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.

Usage

From source file:com.lewa.crazychapter11.Dict.java

private void insertData(SQLiteDatabase db, String word, String detail) {
    db.execSQL("insert into dict values(null,?,?)", new String[] { word, detail });
}

From source file:com.lewa.crazychapter11.DBTest.java

private void insertData(SQLiteDatabase db, String title, String content) {
    db.execSQL("insert into news_inf values(null,?,?)", new String[] { title, content });

    Log.i("DBTest", "insertData 5555");
}

From source file:es.jpv.android.examples.loadersexample.db.DBAsyncTask.java

/**
 * <p>Performs an asynchronous SQL query on the database</p>
 * </p>/*from  w w  w. j  a v  a  2s .c  o m*/
 * @param params The parameters of the query.
 *               <p>params[0] contains an SQL statement with arguments as ?</p>
 *               <p>params[1] contains the arguments of the statament as an array</p>
 *               <p>params[2] contains true if we want the database to be writable</p>
 * @return If an Exception is generated, we return it.
 */
@Override
protected Exception doInBackground(Object... params) {

    String sqlStatement = (String) params[0];
    Object[] sqlParams = (Object[]) params[1];
    boolean writeMode = params[2] != null && (boolean) params[2];

    try {
        SQLiteDatabase database = writeMode ? mDB.getWritableDatabase() : mDB.getReadableDatabase();
        if (sqlParams != null && sqlParams.length != 0) {
            database.execSQL(sqlStatement, sqlParams);
        } else {
            database.execSQL(sqlStatement);
        }

    } catch (Exception e) {
        return e;
    }

    return null;
}

From source file:asu.edu.msse.gpeddabu.moviedescriptions.AddMovie.java

public void onAddButtonClick(View view) throws JSONException {

    // Adding movie title
    EditText tempText = (EditText) findViewById(R.id.titleET);
    String title = tempText.getText().toString();

    // Adding movie Year
    tempText = (EditText) findViewById(R.id.yearET);
    String year = tempText.getText().toString();

    // Adding movie Rated
    tempText = (EditText) findViewById(R.id.ratedET);
    String rated = tempText.getText().toString();

    // Adding movie Released On
    tempText = (EditText) findViewById(R.id.releasedOnET);
    String released = tempText.getText().toString();

    // Adding movie Runtime
    tempText = (EditText) findViewById(R.id.runtimeET);
    String runtime = tempText.getText().toString();

    // Adding movie Genre
    String genre = (String) spinner.getSelectedItem();

    // Adding movie Actors
    tempText = (EditText) findViewById(R.id.actorsET);
    String actors = tempText.getText().toString();

    // Adding movie plot
    tempText = (EditText) findViewById(R.id.plotET);
    String plot = tempText.getText().toString();

    // Adding movie poster url
    tempText = (EditText) findViewById(R.id.posterET);
    String poster = tempText.getText().toString();
    try {/*from ww w  .  j av a 2  s.  c om*/
        MovieDB db = new MovieDB(con);
        SQLiteDatabase crsDB = db.openDB();
        crsDB.execSQL("insert into movie values(?,?,?,?,?,?,?,?,?);",
                new String[] { title, year, rated, released, runtime, genre, actors, plot, poster });
        crsDB.close();
        db.close();
    } catch (Exception ex) {
        android.util.Log.w(this.getClass().getSimpleName(), "Exception adding movie info: " + ex.getMessage());
    }
    Intent ni = new Intent(this, MainActivity.class);
    startActivity(ni);
}

From source file:com.clutch.ClutchStats.java

public void deleteABLogs(double ts) {
    SQLiteDatabase db = this.getWritableDatabase();
    Object[] args = { ts };// w  ww.j a va 2s  .co m
    db.execSQL("DELETE FROM ablog WHERE ts <= ?", args);
    db.close();
}

From source file:com.clutch.ClutchStats.java

public void setCachedChoice(String name, int choice) {
    SQLiteDatabase db = this.getWritableDatabase();
    Object[] args = { name, choice };
    db.execSQL("INSERT INTO abcache (name, choice) VALUES (?, ?)", args);
    db.close();//www .  j a  va 2  s  . c o  m
}

From source file:com.clutch.ClutchStats.java

public void deleteLogs(double beforeOrEqualTo) {
    SQLiteDatabase db = this.getWritableDatabase();
    Object[] args = { beforeOrEqualTo };
    db.execSQL("DELETE FROM stats WHERE ts <= ?", args);
    db.close();//from  w  w  w .ja v  a 2s . co  m
}

From source file:ru.gkpromtech.exhibition.db.DbHelper.java

@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);

    db.execSQL("ATTACH DATABASE ? AS " + SharedData.EXHIBITION_DATABASE_NAME,
            new String[] { getDbPath(mContext, SharedData.EXHIBITION_DATABASE_NAME) });
}

From source file:com.clutch.ClutchStats.java

private void logABData(JSONObject data) {
    SQLiteDatabase db = getWritableDatabase();
    Object[] args = { ClutchUtils.getUUID(), System.currentTimeMillis() / 1000.0, data.toString() };
    db.execSQL("INSERT INTO ablog (uuid, ts, data) VALUES (?, ?, ?)", args);
    db.close();/* w  ww  .j av a  2s .c  o  m*/
}

From source file:com.clutch.ClutchStats.java

public void logAction(String action, Map<String, ?> data) {
    SQLiteDatabase db = getWritableDatabase();
    Object[] args = { ClutchUtils.getUUID(), System.currentTimeMillis() / 1000.0, action,
            new JSONObject(data).toString() };
    db.execSQL("INSERT INTO stats (uuid, ts, action, data) VALUES (?, ?, ?, ?)", args);
    db.close();/*from   www .j  a va 2s  . co  m*/
}