Android에서 기존 sqlite 데이터베이스의 데이터를 업데이트하는 방법

Rahul Bhardwaj

이것은 처음에 21 개의 질문으로 구성된 데이터베이스입니다. 10 개의 질문을 더 추가했지만 데이터베이스에서 업데이트되지 않았습니다.이 데이터베이스에 추가 할 수있는 방법은 Android에 익숙하지 않습니다.

 public class QuizHelper extends SQLiteOpenHelper {
 private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "mathsone";
// tasks table name
private static final String TABLE_QUEST = "quest";
// tasks Table Columns names
private static final String KEY_ID = "qid";
private static final String KEY_QUES = "question";
private static final String KEY_ANSWER = "answer"; // correct option
private static final String KEY_OPTA = "opta"; // option a
private static final String KEY_OPTB = "optb"; // option b
private static final String KEY_OPTC = "optc"; // option c

private SQLiteDatabase dbase;

public QuizHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
    dbase = db;
    String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_QUEST + " ( "
            + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_QUES
            + " TEXT, " + KEY_ANSWER + " TEXT, " + KEY_OPTA + " TEXT, "
            + KEY_OPTB + " TEXT, " + KEY_OPTC + " TEXT)";
    db.execSQL(sql);
    addQuestion();
    // db.close();
}

private void addQuestion() {
    Question q1 = new Question("Who is the president of india ?", "narender modi", "hamid ansari", "pranab mukherji", "pranab mukherji");
    this.addQuestion(q1);
    Question q2 = new Question(" Name of the first university of India  ?", "Nalanda University", "Takshshila University", "BHU", "Nalanda University");
    this.addQuestion(q2);
    Question q3 = new Question("Which college is awarded as Outstanding Engineering Institute North Award”?", "Thapar University", "G.N.D.E.C", "S.L.I.E.T", "G.N.D.E.C");
    this.addQuestion(q3);
    Question q4 = new Question("Name of the first Aircraft Carrier Indian Ship ?", "Samudragupt", "I.N.S. Vikrant", "I.N.S Virat", "I.N.S. Vikrant");
    this.addQuestion(q4);
    Question q5 = new Question("In which town of Punjab the largest grain market of Asia is Available?", "Bathinda", "Khanna", "Ludhiana", "Khanna");
    this.addQuestion(q5);
    Question q6 = new Question("Which is the highest dam in India?", "Bhakhra Dam", "Hirakud Dam", "Tehri Dam", "Tehri Dam");
    this.addQuestion(q6);
    Question q7 = new Question("Which Indian state is having longest coastline ?", "Rajasthan", "Gujrat", "Punjab", "Gujrat");
    this.addQuestion(q7);
    Question q8 = new Question("Name of the first Country to print books ?", "China", "India", "USA", "China");
    this.addQuestion(q8);
    Question q9 = new Question("Study of the Universe is known as?", "Sociology", "Cosmology", "Petology", "Cosmology");
    this.addQuestion(q9);
    Question q10 = new Question("Big Bang theory explains ?", "Origin of Universe.", "Origin of Sun", "Laws of physics.", "Origin of Universe.");
    this.addQuestion(q10);
    Question q11 = new Question("Which Planet is dwarf planet?", "Mercury", "Pluto", "Venus", "Pluto");
    this.addQuestion(q11);
    Question q12 = new Question(" In South Asia,the country with the largest percentage of aged population is ?", "India", "Sri Lanka", "Nepal", "Sri Lanka");
    this.addQuestion(q12);
    Question q13 = new Question("Which is the Largest lake of the world ?", "Caspian Sea ", "Dead Sea", "Arabian sea", "Caspian Sea ");
    this.addQuestion(q13);
    Question q14 = new Question("Which of following industry is famous of Jalandhar city?", "Cycle Parts Industry", "Electronics", "Sports Goods Manufacturing", "Sports Goods Manufacturing");
    this.addQuestion(q14);
    Question q15 = new Question("Capital of Punjab is:", "Ludhiana", "Amritsar", "Chandigarh", "Chandigarh");
    this.addQuestion(q15);
    Question q16 = new Question("How many  Seats of lok sabha are filled by the candidate of Punjab ?", "12", "17", "13", "13");
    this.addQuestion(q16);
    Question q17 = new Question("In Malwa and Doaba regions ____ river separates?", " Beas", "Jehlam", "Satluj", "Satluj");
    this.addQuestion(q17);
    Question q18 = new Question("Which one of the following city of Punjab State was known as Virat Ki Nagri?", "Amritsar", "Dasuha", "Ludhiana", "Dasuha");
    this.addQuestion(q18);
    Question q19 = new Question("Sachin Tendulkar scored his 100th international century against which’ country ?", "Bangladesh", "Australia", "West Indies", "Bangladesh");
    this.addQuestion(q19);
    Question q20 = new Question("What is the minimum permissible age for employment in any factory or mine?", "16", "13", "14", "14");
    this.addQuestion(q20);
    Question q21 = new Question("Where is India's First nuclear centre ?", "Rampur", "Mirapur", "Tarapur", "Tarapur");
    this.addQuestion(q21);
    Question q22= new Question("Srgsbhs","a","b","cd","cd");
    this.addQuestion(q22);
    Question q23= new Question("Srgsbhs","a","b","d","d");
    this.addQuestion(q23);
    Question q24= new Question("Srgsbhs","a","b","f","f");
    this.addQuestion(q24);
    Question q25= new Question("Srgsbhs","a","b","f","f");
    this.addQuestion(q25);
    Question q26= new Question("Srgsbhs","a","b","f","f");
    this.addQuestion(q26);
    Question q27= new Question("Srgsbhs","a","b","f","f");
    this.addQuestion(q27);
    Question q28= new Question("Srgsbhs","a","b","f","f");
    this.addQuestion(q28);
    Question q29= new Question("Srgsbhs","a","b","f","f");
    this.addQuestion(q29);
    Question q30= new Question("Srgsbhs","a","b","f","f");
    this.addQuestion(q30);
    Question q31= new Question("Srgsbhs","a","b","f","f");
    this.addQuestion(q31);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldV, int newV) {
    // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_QUEST);
    // Create tables again
    onCreate(db);
}

// Adding new question
public void addQuestion(Question quest) {
    // SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_QUES, quest.getQUESTION());
    values.put(KEY_ANSWER, quest.getANSWER());
    values.put(KEY_OPTA, quest.getOPTA());
    values.put(KEY_OPTB, quest.getOPTB());
    values.put(KEY_OPTC, quest.getOPTC());

    // Inserting Row
    dbase.insert(TABLE_QUEST, null, values);
}

public List<Question> getAllQuestions() {
    List<Question> quesList = new ArrayList<Question>();
    // Select All Query
    String selectQuery = "SELECT  * FROM " + TABLE_QUEST;
    dbase = this.getReadableDatabase();
    Cursor cursor = dbase.rawQuery(selectQuery, null);
    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        do {
            Question quest = new Question();
            quest.setID(cursor.getInt(0));
            quest.setQUESTION(cursor.getString(1));
            quest.setANSWER(cursor.getString(2));
            quest.setOPTA(cursor.getString(3));
            quest.setOPTB(cursor.getString(4));
            quest.setOPTC(cursor.getString(5));

            quesList.add(quest);
        } while (cursor.moveToNext());
    }
    // return quest list
    return quesList;
}

}

디에고 토레스 밀란

DB 업그레이드를 강제하려면 번호를 늘리거나 addQuestions()다른 위치에서 호출하십시오 .onCreate()DATABASE_VERSION

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

한 데이터베이스 (기본 serevr (sql))에서 Android 데이터베이스 (로컬 (sqlite))의 다른 데이터베이스로 데이터를 이동하는 방법

분류에서Dev

기존 SQLite 데이터베이스에 열을 다시 쓰는 (복사) 방법

분류에서Dev

Firestore 데이터베이스의 기존 문서에 데이터를 추가하는 방법

분류에서Dev

SQLite 데이터베이스에서 Android의 문자열 형식으로 데이터를 검색하는 방법

분류에서Dev

Android sqlite에서 데이터베이스 테이블을 업데이트하는 방법 ..?

분류에서Dev

목록보기 데이터를 SQLite 데이터베이스에 전달하는 방법은 무엇입니까?

분류에서Dev

자산 폴더에서 sqlite 데이터베이스를 업데이트하는 방법은 무엇입니까?

분류에서Dev

android sqlite 데이터베이스에서 새 행을 업데이트하는 방법

분류에서Dev

Android의 SQLite 데이터베이스-제거하는 방법?

분류에서Dev

Firebase 실시간 데이터베이스의 기존 데이터베이스에 데이터를 추가하는 방법은 무엇입니까?

분류에서Dev

iOS에서 데이터 SQLite 데이터베이스 쓰기 / 업데이트

분류에서Dev

ROBLOX의 SQLite 데이터베이스에서 읽는 방법

분류에서Dev

Xamarin의 SQLite 데이터베이스에서 데이터를 삭제하는 방법

분류에서Dev

sqlite 데이터베이스 android에서 데이터 쓰기

분류에서Dev

Android의 sqlite 데이터베이스에서 임의 데이터 가져 오기

분류에서Dev

Android의 SQLite 데이터베이스에서 이름을 얻는 방법

분류에서Dev

Android의 Sqlite 데이터베이스에서 테이블을 만드는 방법

분류에서Dev

mysql 데이터베이스의 기존 행에서 데이터 업데이트

분류에서Dev

Android 백업 후 Sqlite 데이터베이스를 복원하는 방법

분류에서Dev

Android에서 sqlite 데이터베이스를 정렬하는 방법

분류에서Dev

Flutter에서 기존 Sqlite 데이터베이스 가져 오기

분류에서Dev

Android-SQLite 데이터베이스에서 데이터를 검색하는 가장 빠른 방법

분류에서Dev

목록의 데이터를 SQLite3 데이터베이스에 삽입하는 방법

분류에서Dev

Android의 SQLite 데이터베이스에서 ListView 채우기

분류에서Dev

Laravel 7에서 외래 키로 DB의 기존 데이터를 업데이트하는 방법

분류에서Dev

Android SQLite 데이터베이스의 열에서 값을 가져 오는 방법

분류에서Dev

Android의 SQLite 데이터베이스에서 null 값을 얻는 방법

분류에서Dev

MySQL 데이터베이스 A의 테이블에서 데이터베이스 B의 기존 테이블에 행을 추가하는 방법

분류에서Dev

MySQL 데이터베이스에 데이터를 추가하는 기본 방법

Related 관련 기사

  1. 1

    한 데이터베이스 (기본 serevr (sql))에서 Android 데이터베이스 (로컬 (sqlite))의 다른 데이터베이스로 데이터를 이동하는 방법

  2. 2

    기존 SQLite 데이터베이스에 열을 다시 쓰는 (복사) 방법

  3. 3

    Firestore 데이터베이스의 기존 문서에 데이터를 추가하는 방법

  4. 4

    SQLite 데이터베이스에서 Android의 문자열 형식으로 데이터를 검색하는 방법

  5. 5

    Android sqlite에서 데이터베이스 테이블을 업데이트하는 방법 ..?

  6. 6

    목록보기 데이터를 SQLite 데이터베이스에 전달하는 방법은 무엇입니까?

  7. 7

    자산 폴더에서 sqlite 데이터베이스를 업데이트하는 방법은 무엇입니까?

  8. 8

    android sqlite 데이터베이스에서 새 행을 업데이트하는 방법

  9. 9

    Android의 SQLite 데이터베이스-제거하는 방법?

  10. 10

    Firebase 실시간 데이터베이스의 기존 데이터베이스에 데이터를 추가하는 방법은 무엇입니까?

  11. 11

    iOS에서 데이터 SQLite 데이터베이스 쓰기 / 업데이트

  12. 12

    ROBLOX의 SQLite 데이터베이스에서 읽는 방법

  13. 13

    Xamarin의 SQLite 데이터베이스에서 데이터를 삭제하는 방법

  14. 14

    sqlite 데이터베이스 android에서 데이터 쓰기

  15. 15

    Android의 sqlite 데이터베이스에서 임의 데이터 가져 오기

  16. 16

    Android의 SQLite 데이터베이스에서 이름을 얻는 방법

  17. 17

    Android의 Sqlite 데이터베이스에서 테이블을 만드는 방법

  18. 18

    mysql 데이터베이스의 기존 행에서 데이터 업데이트

  19. 19

    Android 백업 후 Sqlite 데이터베이스를 복원하는 방법

  20. 20

    Android에서 sqlite 데이터베이스를 정렬하는 방법

  21. 21

    Flutter에서 기존 Sqlite 데이터베이스 가져 오기

  22. 22

    Android-SQLite 데이터베이스에서 데이터를 검색하는 가장 빠른 방법

  23. 23

    목록의 데이터를 SQLite3 데이터베이스에 삽입하는 방법

  24. 24

    Android의 SQLite 데이터베이스에서 ListView 채우기

  25. 25

    Laravel 7에서 외래 키로 DB의 기존 데이터를 업데이트하는 방법

  26. 26

    Android SQLite 데이터베이스의 열에서 값을 가져 오는 방법

  27. 27

    Android의 SQLite 데이터베이스에서 null 값을 얻는 방법

  28. 28

    MySQL 데이터베이스 A의 테이블에서 데이터베이스 B의 기존 테이블에 행을 추가하는 방법

  29. 29

    MySQL 데이터베이스에 데이터를 추가하는 기본 방법

뜨겁다태그

보관