harian untung99play.xyz

untung99play.xyz: Cara Membuat CRUD SQLite Database Android Studio


Untung99 menawarkan beragam permainan yang menarik, termasuk slot online, poker, roulette, blackjack, dan taruhan olahraga langsung. Dengan koleksi permainan yang lengkap dan terus diperbarui, pemain memiliki banyak pilihan untuk menjaga kegembiraan mereka. Selain itu, Untung99 juga menyediakan bonus dan promosi menarik yang meningkatkan peluang kemenangan dan memberikan nilai tambah kepada pemain.

Berikut adalah artikel atau berita tentang Harian untung99play.xyz dengan judul untung99play.xyz: Cara Membuat CRUD SQLite Database Android Studio yang telah tayang di untung99play.xyz terimakasih telah menyimak. Bila ada masukan atau komplain mengenai artikel berikut silahkan hubungi email kami di [email protected], Terimakasih.


Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/farizdot/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Pada tutorial pemrograman android kali ini kita akan membahas mengenai CRUD SQLite Database. Apa itu CRUD ? CRUD ini adalah singkatan dari Create Read Update Delete. Apa itu SQLite ? SQLite ini kalau menurut versi saya adalah tempat penyimpanan suatu data atau database yang tempatnya ada di local storage device android. Kalau dari situs resminya SQLite ini adalah SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don’t need to establish any kind of connections for it like JDBC,ODBC e.t.c

Cara Membuat CRUD SQLite Database Android Studio

Pada tutorial pemrograman android ini, untuk membuat databasenya kita akan menggunakan bantuan library Greendao. Library Greendao ini adalah library buatan dari GreenRobot, Nah daripada bingung saya akan mengkutip istilah Greendao ini itu apa. Menurut situs resminya : greenDAO is an open source Android ORM making development for SQLite databases fun again. It relieves developers from dealing with low-level database requirements while saving development time. SQLite is an awesome embedded relational database. Still, writing SQL and parsing query results are quite tedious and time-consuming tasks. greenDAO frees you from these by mapping Java objects to database tables (called ORM, “object/relational mapping”). This way you can store, update, delete, and query for Java objects using a simple object oriented API.

Ada apa aja fitur dari Greendao ini ?

  • Maximum performance (probably the fastest ORM for Android); our benchmarks are open sourced too
  • Easy to use powerful APIs covering relations and joins
  • Minimal memory consumption
  • Small library size (<100kb)>
  • Database encryption: greenDAO supports SQLCipher to keep your user’s data safe
  • Strong community: More than 5.000 GitHub stars show there is a strong and active community

Kalian bisa mengunjungi situs resminya di http://greenrobot.org/greendao/

Nah, Dari sini kalian sudah tau maksud dari tujuan artikel Cara Membuat CRUD SQLite Database Android Studio ini itu apa. Sekarang kita masuk ke bagaimana cara implementasi CRUD SQLite Database, lets coding!

Persiapan nama project

Buat project dengan nama SampleCrudGreendao.

Tambahkan library Greendao dan library pendukung lainnya

Buka file build.gradle ( module:app ) lalu tambahkan beberapa code seperti berikut :

apply plugin: ‘com.android.application’

apply plugin: ‘org.greenrobot.greendao’ // <-->

        applicationId “com.app.samplecrudgreendao”

        testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner”

            proguardFiles getDefaultProguardFile(‘proguard-android-optimize.txt’), ‘proguard-rules.pro’

    implementation fileTree(dir: ‘libs’, include: [‘*.jar’])

    implementation ‘com.android.support:appcompat-v7:28.0.0’

    implementation ‘com.android.support.constraint:constraint-layout:1.1.3’

    implementation ‘com.android.support:design:28.0.0’ // <-->

    implementation ‘com.android.support:cardview-v7:28.0.0’ // <-->

    implementation ‘com.android.support:recyclerview-v7:28.0.0’ // <-->

    implementation ‘com.jakewharton:butterknife:8.8.0’ // <-->

    implementation ‘org.greenrobot:greendao:3.2.2’ // <-->

    annotationProcessor ‘com.jakewharton:butterknife-compiler:8.8.0’ // <-->

    testImplementation ‘junit:junit:4.12’

    androidTestImplementation ‘com.android.support.test:runner:1.0.2’

    androidTestImplementation ‘com.android.support.test.espresso:espresso-core:3.0.2’

#NOTE :

Untuk penambahan kodenya kalian hanya cukup meng-copy paste / mengetik yang ada tanda “Add this line”nya saja.

Library Greendao pada root gradle

Buka file build.gradle (Project : SampleCrudGreendao) lalu tambahkan kode seperti berikut :

// Top-level build file where you can add configuration options common to all sub-projects/modules.

        classpath ‘com.android.tools.build:gradle:3.3.1’

        classpath ‘org.greenrobot:greendao-gradle-plugin:3.2.2’ // <-->

        // NOTE: Do not place your application dependencies here; they belong

        // in the individual module build.gradle files

    delete rootProject.buildDir

Sync Project

Jika semua sudah tercopy – paste kalian bisa langsung mengklik action button “Sync Now” agar proses pengambilan library segera diproses.

Persiapan struktur folder

Buatlah sebuah package folder dengan nama – nama folder sebagai berikut :

-create

-edit

-home

-utils

–database

Cara Membuat CRUD SQLite Database Android Studio-1

Buat class TblPengeluaran

Didalem folder database tambahkan class baru dengan nama TblPengeluaran. Lalu isi dengan kode berikut :

public class TblPengeluaran

    private Long idTblPengeluaran;

    private String pengeluaran;

#NOTE :

Anotasi @Entitiy ini adalah untuk kasih tau ke generatornya si Greendao bahwa class ini adalah untuk menjadi struktur tabelnya. Lalu untuk @Id(autoincrement = true) ini adalah kasih tau ke generator bahwa idTblPengeluaran ini bentuknya unik atau bertambah setiap saat. Jadi kurang lebih maksud class ini untuk membuat struktur tabel pada databasenya.

Build Generator

Jika kalian sudah membuat class untuk pengaturan tabelnya, Sekarang kamu klik icon palu ( build ) lalu tungu beberapa saat. Fungsi itu untuk menjalankan generator Greendaonya.

Nanti secara otomatis Greendao akan membuat class untuk kebutuhan development kita. Hasil kode yang kita build adalah sebagai berikut :

package com.app.samplecrudgreendao.utils.database;

import org.greenrobot.greendao.annotation.Entity;

import org.greenrobot.greendao.annotation.Id;

import org.greenrobot.greendao.annotation.Generated;

* Created by Fariz Ramadhan.

* website : https://farizdotid.com/

* github : https://github.com/farizdotid

* linkedin : https://www.linkedin.com/in/farizramadhan/

public class TblPengeluaran

    private Long idTblPengeluaran;

    private String pengeluaran;

    @Generated(hash = 388400954)

    public TblPengeluaran(Long idTblPengeluaran, String pengeluaran, int nominal)

        this.idTblPengeluaran = idTblPengeluaran;

        this.pengeluaran = pengeluaran;

    @Generated(hash = 177408923)

    public Long getIdTblPengeluaran()

        return this.idTblPengeluaran;

    public void setIdTblPengeluaran(Long idTblPengeluaran)

        this.idTblPengeluaran = idTblPengeluaran;

    public String getPengeluaran()

    public void setPengeluaran(String pengeluaran)

        this.pengeluaran = pengeluaran;

    public void setNominal(int nominal)

Buat class DaoHandler

Tambahkan class baru dengan nama DaoHandler lalu tambahkan fungsi static untuk memanggil DaoSession. Untuk kodenya seperti berikut :

    public static DaoSession getInstance(Context context)

        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, “catatpengeluaran_db”, null);

        SQLiteDatabase db = helper.getWritableDatabase();

        DaoMaster daoMaster = new DaoMaster(db);

        return daoMaster.newSession();

#NOTE :

Pada value “catatpengeluaran_db” ini adalah nama databasenya. Class ini berfunsi untuk kebutuhan inisialisasi pengaturan Greendao, Nantinya kalian hanya tinggal panggil kode ini saja untuk memanggil fungsi Greendao seperti get tabel pada database ataupun kebutuhan-kebutuhan SQLite lainnya.

Buat class FunctionHelper

Pada package utils, tambahkan class baru dengan nama FunctionHelper. Class ini berfungsi untuk menyompan beberapa fungsi yang dibutuhkan nantinya supaya fungsi yang dibuat tidak berulang-ulang.

Menambahkan fungsi

Pada class FunctionHelper buatlah sebuah fungsi untuk meng-convert suatu nilai ke dalam format uang rupiah. Untuk kodenya seperti ini :

Fungsi untuk mengconvert sebuah nilai menjadi format Rupiah.

Contoh : 1000 akan menjadi Rp1.000

public static String convertRupiah(int nominal)

    Locale localeID = new Locale(“in”, “ID”);

    NumberFormat formatRupiah = NumberFormat.getCurrencyInstance(localeID);

    return formatRupiah.format(nominal);

Buat activity CreateActivity

Pada folder atau package create tambahkan activity baru dengan nama CreateActivity. CreateActivity ini untuk membuat data sesuai dengan kebutuhan user.

Layout activity create

Buka layout activity_create, Lalu isi dengan beberapa widget seperti ini :

xml version=”1.0″ encoding=”utf-8″?>

    xmlns:android=”http://schemas.android.com/apk/res/android”

    xmlns:app=”http://schemas.android.com/apk/res-auto”

    xmlns:tools=”http://schemas.android.com/tools”

    android:layout_width=”match_parent”

    android:layout_height=”match_parent”

    android:orientation=”vertical”

    tools:context=”.create.CreateActivity”>

        android:layout_width=”match_parent”

        android:layout_height=”wrap_content”

        android:hint=”@string/title_pembelian”>

            android:id=”@+id/etPembelian”

            android:layout_width=”match_parent”

            android:layout_height=”wrap_content”

            android:inputType=”textMultiLine”

            android:textColor=”@color/primary_text”

            android:fontFamily=”@font/notosans_regular”/>

        android:layout_width=”match_parent”

        android:layout_height=”wrap_content”

        android:layout_marginTop=”16dp”

        android:hint=”@string/title_nominal”>

            android:id=”@+id/etNominal”

            android:layout_width=”match_parent”

            android:layout_height=”wrap_content”

            android:inputType=”number”

            android:textColor=”@color/primary_text”

            android:fontFamily=”@font/notosans_regular” />

        android:id=”@+id/btnSimpan”

        android:layout_width=”match_parent”

        android:layout_height=”wrap_content”

        android:fontFamily=”@font/notosans_bold”

        android:layout_marginTop=”16dp”

        android:text=”@string/title_simpan”

        android:textColor=”@android:color/white”

        android:background=”@color/colorPrimaryDark”/>

Inisialisasi Komponen

Pada class CreateActivity lalu inisialisasikan komponen widget yang sudah kita buat pada layout activity_create dan inisialisasi beberapa class untuk kebutuhan Create ini.

@BindView(R.id.etPembelian)

@BindView(R.id.etNominal)

@BindView(R.id.btnSimpan)

private DaoSession daoSession;

Lalu didalam onCreate tambahkan kode berikut :

Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);

        getSupportActionBar().setDisplayShowHomeEnabled(true);

        getSupportActionBar().setTitle(“Buat pengeluaran”);

        unbinder = ButterKnife.bind(this);

        daoSession = DaoHandler.getInstance(this);

        btnSimpan.setOnClickListener(new View.OnClickListener()

            public void onClick(View v)

                String pembelian = etPembelian.getText().toString();

                String nominal = etNominal.getText().toString();

                if (pembelian.isEmpty()