Save current time and end time in sqlite bank

0

I'm developing a project on home automation and now when I click on the CONNECT button it would perform the following functions: start device, start timer, save current time and send to the database.

Clicking the Shut down button would turn off the device, stopwatch would be reset, the current device shutdown time would be saved and sent to the bank.

When attempting to save the current time when you click ON, the following error occurs:

05-30 12:31:25.874    2192-2192/com.example.jhow.tecnumautomao E/SQLiteLog﹕ (1299) abort at 5 in [INSERT INTO contacts(tempoInicial) VALUES (?)]: NOT NULL constraint failed: contacts.name
05-30 12:31:25.895    2192-2192/com.example.jhow.tecnumautomao E/SQLiteDatabase﹕ Error inserting tempoInicial=12:31:25
    android.database.sqlite.SQLiteConstraintException: NOT NULL constraint failed: contacts.name (code 1299)
            at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
            at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:782)
            at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
            at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
            at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1471)
            at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
            at com.example.jhow.tecnumautomao.Persistencia.PessoaDAO.dadosTimeInicial(PessoaDAO.java:158)
            at com.example.jhow.tecnumautomao.lampada_quarto$1.onClick(lampada_quarto.java:77)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

This is also a time-saving method for the bank:

DBSQLITE CLASS TABLE:

 public void onCreate(SQLiteDatabase db) {

    String TABLE_CREATE =

            "CREATE TABLE " + Pessoa.TABLE_NAME  + "("
            + Pessoa.COLUNA_ID  + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
            + Pessoa.COLUNA_NOME + " TEXT, "
            + Pessoa.COLUNA_UNAME + " TEXT, "
            + Pessoa.COLUNA_EMAIL + " TEXT, "
            + Pessoa.COLUNA_PASS + " TEXT, "
            + Pessoa.COLUNA_TIME_INICIAL + " TEXT, "
            + Pessoa.COLUNA_TIME_FINAL + " TEXT "
            + Pessoa.COLUNA_SENHA1 + " TEXT, "
            + Pessoa.COLUNA_SENHA2 + " TEXT )";

    db.execSQL(TABLE_CREATE);
    this.db = db;


}

METHODS TO SAVE TIME

public void dadosTimeInicial(){

    SQLiteDatabase db = dbsqLite.getWritableDatabase();

    SimpleDateFormat dateFormat_hora = new SimpleDateFormat("HH:mm:ss");


    Date data = new Date();
    Calendar  cal = Calendar.getInstance();
    cal.setTime(data);
    Date data_atual = cal.getTime();

    String hora_atual = dateFormat_hora.format(data_atual);

    ContentValues values = new ContentValues();
    values.put(Pessoa.COLUNA_TIME_INICIAL, hora_atual);

    db.insert(Pessoa.TABLE_NAME, null , values );
    db.close();
}

 public void dadosTimeFinal (){


    SQLiteDatabase db = dbsqLite.getWritableDatabase();

    SimpleDateFormat dateFormat_hora = new SimpleDateFormat("HH:mm:ss");


    Date data = new Date();
    Calendar  cal = Calendar.getInstance();
    cal.setTime(data);
    Date data_atual = cal.getTime();

    String hora_atual = dateFormat_hora.format(data_atual);

    ContentValues values = new ContentValues();
    values.put(Pessoa.COLUNA_TIME_FINAL, hora_atual);

    db.insert(Pessoa.TABLE_NAME, null , values );
    db.close();
    
asked by anonymous 30.05.2017 / 14:51

0 answers