Home > Mobile >  Learning database problems.
Learning database problems.

Time:11-05

Small white just to learn the basic knowledge of database, how to do it as video open the db files, without the data, a all have no, the great god, please answer, thank you,
 import android. The content. The Context; 
The import android. Database. Sqlite. SQLiteDatabase;
The import android. Database. Sqlite. SQLiteOpenHelper;

Public class NotesDB extends SQLiteOpenHelper {

Public static final String TABLE_NAME="notes";
Public static final String CONTENT="CONTENT";
Public static final String ID="_id";
Public static final String TIME="TIME";

Public NotesDB Context (Context) {
Super (context, "notes", null, 1);
}

@ Override
Public void onCreate (SQLiteDatabase db) {
Db. ExecSQL (TABLE_NAME "CREATE TABLE" + + "(" + ID
+ "INTEGER PRIMARY KEY AUTOINCREMENT," + CONTENT
+ TEXT NOT NULL, "" + TIME +" TEXT NOT NULL) ");
}

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

}
}



This is the main activity
 
The import android. The Manifest;
The import android. Content. ContentValues;
The import android. Database. Sqlite. SQLiteDatabase;
The import android. Support. V7. App. AppCompatActivity;
The import android. OS. Bundle;
import android.widget.TextView;
The import android. Widget. Toast;

The import com. Ysuper2009. Note. R;
The import com. Ysuper2009. Note. Db. NotesDB;
The import com. Ysuper2009. Note. Util. YPermissionManager;

Import the Java. Text. SimpleDateFormat;
Import the Java. Util. Date;
import java.util.List;

The import pub. Devrel. Easypermissions. AppSettingsDialog;
The import pub. Devrel. Easypermissions. Easypermissions;


Public class MainActivity extends AppCompatActivity {

Private String [] perms={Manifest. Permission. The CAMERA, the Manifest. Permission. WRITE_EXTERNAL_STORAGE};
private TextView tv;
//database content
Private NotesDB NotesDB;
Private SQLiteDatabase dbWriter;

@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Activity_main);
TV=(TextView) the findViewById (R.i which x);


//YPermissionManager YPermissionManager=new YPermissionManager ();
//yPermissionManager checkBasePermission (this, perms);

NotesDB=new notesDB (this);
DbWriter=notesDB. GetWritableDatabase ();
The add ();

}

Public void the add () {
ContentValues CV=new ContentValues ();
CV. Put (NotesDB. The CONTENT, "tongtong");
CV. Put (NotesDB. TIME, getTime ());
DbWriter. Insert (NotesDB TABLE_NAME, null, CV);

}

Public String getTime () {
SimpleDateFormat format=new SimpleDateFormat (" on dd MM yyyy years HH: MM: ss ");
The Date curDate=new Date ();
String STR=format. The format (curDate);
TV. SetText (STR);
return str;
}

/*
@ Override
Public void onRequestPermissionsResult (int requestCode, String [] permissions, int [] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
EasyPermissions. OnRequestPermissionsResult (requestCode, permissions, grantResults);
}

@ Override
Public void onPermissionsGranted (int requestCode List Perms) {
Toast. MakeText (this, "permission is ok, do use it," Toast. LENGTH_SHORT), show ();
}

@ Override
Public void onPermissionsDenied (int requestCode List Perms) {
Toast. MakeText (this, "permission to fail", Toast. LENGTH_SHORT), show ();
If (EasyPermissions. SomePermissionPermanentlyDenied (this, perms)) {
New AppSettingsDialog. Builder (this). The build (), show ();
}
}

*/

}

CodePudding user response:


As in the open plug-in is like this, without the data,

CodePudding user response:

Forgot to say, with MAC

CodePudding user response:

Online, etc.,,,,,,,,,,

CodePudding user response:

Don't seem to create success,,,

CodePudding user response:

Look at the data, and forgot to add the close, ha ha,

The
reference 4 floor gxh_apologize reply:
seems to be no create success,,,

CodePudding user response:

Suggest you learn androidx. Room. *, compared with the manual operation SQLite, developing more efficient,
  • Related