title: Insert in SQLite Database - Android
body: <p>I'm currently working on my Android class project. I have some trouble with the insert statement in the database; I am using SQLite. When I'm running the application my database is correctly created but values are not inserted. I tried to refer my self to online proposals and solutions and i tried implementing it but with no avail.</p>
  
  <p>Please I need some help.
  Thanks.</p>
  
  <p>DBHandler.java</p>
  
  <pre><code>package ck.edu.com.birch;
  
  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;
  import android.util.Log;
  
  import java.text.SimpleDateFormat;
  import java.util.Date;
  
  public class DBHandler {
  
      String TAG = "Tennis Tracker";
  
      String DB_NAME = "TennisEFREI.db";
      String DB_TABLE = "statistics";
      int DB_VERSION = 1;
  
      String SQL_CREATE = "CREATE TABLE " + DB_TABLE +
              " (_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
              "playerOnename TEXT NOT NULL, " +
              "playerTwoname TEXT NOT NULL, " +
              "winner TEXT NOT NULL, " +
              "wonPointsPlayer1 INTEGER NOT NULL, " +
              "wonPointsPlayer2 INTEGER NOT NULL, " +
              "wonSetsPlayer1 INTEGER NOT NULL, " +
              "wonSetsPlayer2 INTEGER NOT NULL, " +
              "acePlayer1 INTEGER, " +
              "acePlayer2 INTEGER, " +
              "winPlayer1 INTEGER, " +
              "winPlayer2 INTEGER, " +
              "errorPlayer1 INTEGER, " +
              "errorPlayer2 INTEGER, " +
              "date TIMESTAMP DEFAULT CURRENT_TIMESTAMP)";
      String SQL_DROP = "DROP TABLE IF EXISTS " + DB_TABLE;
  
      DatabaseHelper databaseHelper;
  
      private SQLiteDatabase db;
  
      public DBHandler(Context context) {
          databaseHelper = new DatabaseHelper(context);
      }
  
      class DatabaseHelper extends SQLiteOpenHelper {
          DatabaseHelper(Context context) {
              super(context, DB_NAME, null, DB_VERSION);
          }
  
  
          @Override
          public void onCreate(SQLiteDatabase db) {
              db.execSQL(SQL_CREATE);
  
          }
  
          @Override
          public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
              db.execSQL(SQL_DROP);
              onCreate(db);
          }
      }
  
      public void open() throws SQLException {
          db = databaseHelper.getWritableDatabase();
      }
  
      public void close() {
          databaseHelper.close();
      }
  
      public long insertStatistics(String playerOnename, String playerTwoname, String winner, int wonPointsPlayer1, int wonPointsPlayer2, int wonSetsPlayer1, int wonSetsPlayer2, int acePlayer1, int acePlayer2, int winPlayer1, int winPlayer2, int errorPlayer1, int errorPlayer2) {
          SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
          String date = simpleDateFormat.format(new Date());
          ContentValues contentValues = new ContentValues();
          contentValues.put("playerOnename", playerOnename);
          contentValues.put("playerTwoname", playerTwoname);
          contentValues.put("winner", winner);
          contentValues.put("wonPointsPlayer1", wonPointsPlayer1);
          contentValues.put("wonPointsPlayer2", wonPointsPlayer2);
          contentValues.put("wonSetsPlayer1", wonSetsPlayer1);
          contentValues.put("wonSetsPlayer2", wonPointsPlayer2);
          contentValues.put("acePlayer1", acePlayer1);
          contentValues.put("acePlayer2", acePlayer2);
          contentValues.put("winPlayer1", winPlayer1);
          contentValues.put("winPlayer2", winPlayer2);
          contentValues.put("errorPlayer1", errorPlayer1);
          contentValues.put("errorPlayer2", errorPlayer2);
          contentValues.put("date", date);
          Log.d(TAG, "VALUES : " + contentValues);
          return db.insert(DB_TABLE, null, contentValues);
      }
  }
  
  
  </code></pre>