Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6469435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:59:26+00:00 2026-05-25T05:59:26+00:00

My Database Adapter code is as like below: package com.quiz.spellingquiz; import java.io.IOException; import android.content.ContentValues;

  • 0

My Database Adapter code is as like below:

package com.quiz.spellingquiz;
import java.io.IOException;

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.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class DBAdapter 
{
    //  Database Operation
    public static final String KEY_ROWID = "_id";
    public static final String KEY_ISBN = "isbn";
    public static final String KEY_TITLE = "title";
    public static final String KEY_WORD = "word";
    public static final String KEY_SOUND = "sound";
    public static final String KEY_PUBLISHER = "publisher";    
    private static final String TAG = "DBAdapter";
    private static final String DATABASE_NAME = "testing";
    public static String DATABASE_TABLE = null;
    private static final int DATABASE_VERSION = 1;

    public static final String DATABASE_CREATE =
        "create table "+DATABASE_TABLE+" (_id integer primary key, "
        + "isbn text not null," 
        + "title text not null,"
        + "word text not null,"
        + "sound text not null,"
        + "publisher text not null);";


    private final Context context; 

    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;


    public DBAdapter(Context ctx, String table_name) 
    {
        this.context = ctx;
        DATABASE_TABLE=table_name;
        DBHelper = new DatabaseHelper(context);
    }

    private static class DatabaseHelper extends SQLiteOpenHelper 
    {
        DatabaseHelper(Context context) 
        {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) 
        {
            db.execSQL(DATABASE_CREATE);

        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion,int newVersion) 
        {
            Log.w(TAG, "Upgrading database from version "+oldVersion+" to "+newVersion+", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS "+DATABASE_TABLE);
            onCreate(db);
        }
    }    

    //---opens the database---
    public DBAdapter open() throws SQLException 
    {
        db = DBHelper.getWritableDatabase();
        return this;
    }

    //---closes the database---    
    public void close() 
    {
        DBHelper.close();
    }

    //---insert a title into the database---
    public long insertTitle(String isbn, String title, String word, String sound, String publisher) 
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_ISBN, isbn);
        initialValues.put(KEY_TITLE, title);
        initialValues.put(KEY_WORD, word);
        initialValues.put(KEY_SOUND, sound);
        initialValues.put(KEY_PUBLISHER, publisher);
        return db.insert(DATABASE_TABLE, null, initialValues);
    }

    //---deletes a particular title---
    public boolean deleteTitle(long rowId) 
    {
        return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
    }

    public boolean deleteAllTitle()
    {
        return db.delete(DATABASE_TABLE,null, null)>0;
    }
    public Cursor getAllTitles() 
    {
        Cursor mCursor = db.query(DATABASE_TABLE, new String[] {
                KEY_ROWID, 
                KEY_ISBN,
                KEY_TITLE,
                KEY_WORD,
                KEY_SOUND,
                KEY_PUBLISHER}, 
                null, 
                null, 
                null,
                null, 
                null,
                null);

        return mCursor;
    }


    //---retrieves a particular title---
    public Cursor getTitle(long rowId) throws SQLException 
    {
        Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {
                        KEY_ROWID,
                        KEY_ISBN, 
                        KEY_TITLE,
                        KEY_WORD,
                        KEY_SOUND,
                        KEY_PUBLISHER
                        }, 
                        KEY_ROWID + "=" + rowId, 
                        null,
                        null, 
                        null, 
                        null, ////////////////////////////
                        null);
        if (mCursor != null) 
        {
            mCursor.moveToFirst();
        }
        return mCursor;
    }
    // to fetch TextFile with Sound file
    public Cursor getSound(String str) throws SQLException
    {
        String file = Environment.getExternalStorageDirectory().getAbsolutePath();
        file = file+"/"+str+".3gp";

        Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {
                    KEY_ROWID,
                    KEY_ISBN, 
                    KEY_TITLE,
                    KEY_WORD,
                    KEY_SOUND,
                    KEY_PUBLISHER
                }, 
                KEY_SOUND + "=" +file, 
                null,
                null, 
                null, 
                null,
                null);
if (mCursor != null) 
{
    mCursor.moveToFirst();
}
return mCursor;

    }

    public void deleteAll()
    {
        this.db.delete(DATABASE_TABLE, null, null);
    }

    //---updates a title---
    public boolean updateTitle(long rowId, String isbn, String title,String word,String sound, String publisher) 
    {
        ContentValues args = new ContentValues();
        args.put(KEY_ISBN, isbn);
        args.put(KEY_TITLE, title);
        args.put(KEY_WORD, word);
        args.put(KEY_SOUND, sound);
        args.put(KEY_PUBLISHER, publisher);
        return db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
    }
}

Now in another activity i make the DatabaseAdapter object with the table name like this:

final DBAdapter db = new DBAdapter(this,table_name); // create new database with givan table name

Now while i fetch the data from that object, it gives me error like :

android.database.sqlite.SQLiteException: no such table: hello: , while compiling: INSERT INTO hello(word, title, sound, publisher, isbn) VALUES(?, ?, ?, ?, ?);

So where i am wrong? Why i am not able to create the table? What should i have to do ?

See This is My code of another activity from where i m calling the DBAdapter

  // database object        
    final DBAdapter db = new DBAdapter(this); // create new database with givan table name


    showall.setOnClickListener(new View.OnClickListener() 
    {

        public void onClick(View v) 
        {
            db.open();
            Cursor c = db.getAllTitles();
            while(c.moveToNext())        
            {
                Toast.makeText(EnterWordsActivity.this,
                        "id: " + c.getString(0) + "\n" + 
                        "ISBN: " + c.getString(1) + "\n" +  
                        "TITLE: " + c.getString(2) + "\n" + 
                        "WORD: " + c.getString(3) + "\n" +
                        "SOUND:" + c.getString(4) +"\n"+
                        "PUBLISHER:  " + c.getString(5),Toast.LENGTH_LONG).show();
            }
            db.close();
        }
    });

Error log after creating new table in to same database.

09-01 15:05:52.608: ERROR/AndroidRuntime(596): FATAL EXCEPTION: main

09-01 15:05:52.608: ERROR/AndroidRuntime(596): android.database.sqlite.SQLiteException: no such table: world: , while compiling: SELECT _id, isbn, title, word, sound, publisher FROM world
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.database.sqlite.SQLiteCompiledSql.(SQLiteCompiledSql.java:64)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:80)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:46)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1301)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at com.quiz.spellingquiz.DBAdapter.getAllTitles(DBAdapter.java:119)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at com.quiz.spellingquiz.EnterWordsActivity$1.onClick(EnterWordsActivity.java:86)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.view.View.performClick(View.java:2408)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.view.View$PerformClick.run(View.java:8816)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.os.Handler.handleCallback(Handler.java:587)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.os.Handler.dispatchMessage(Handler.java:92)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.os.Looper.loop(Looper.java:123)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at java.lang.reflect.Method.invokeNative(Native Method)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at java.lang.reflect.Method.invoke(Method.java:521)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-01 15:05:52.608: ERROR/AndroidRuntime(596): at dalvik.system.NativeStart.main(Native Method)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:59:27+00:00Added an answer on May 25, 2026 at 5:59 am

    use this code

     import java.io.IOException;
    
    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.media.MediaPlayer;
    import android.media.MediaRecorder;
    import android.os.Environment;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    
    public class DBAdapter 
    {
    //  Database Operation
    public static final String KEY_ROWID = "_id";
    public static final String KEY_ISBN = "isbn";
    public static final String KEY_TITLE = "title";
    public static final String KEY_WORD = "word";
    public static final String KEY_SOUND = "sound";
    public static final String KEY_PUBLISHER = "publisher";    
    private static final String TAG = "DBAdapter";
    private static final String DATABASE_NAME = "testing";
    public static String DATABASE_TABLE = null;
    private static final int DATABASE_VERSION = 1;
    
    public static final String DATABASE_CREATE =
        "create table "+DATABASE_TABLE+" (_id integer primary key, "
        + "isbn text not null," 
        + "title text not null,"
        + "word text not null,"
        + "sound text not null,"
        + "publisher text not null);";
    
    
    private final Context context; 
    
    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;
    
    
    public DBAdapter(Context ctx, String table_name) 
    {
        this.context = ctx;
        DATABASE_TABLE=table_name;
        DBHelper = new DatabaseHelper(context);
    }
    
    private static class DatabaseHelper extends SQLiteOpenHelper 
    {
        DatabaseHelper(Context context) 
        {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
    
        @Override
        public void onCreate(SQLiteDatabase db) 
        {
            db.execSQL(DATABASE_CREATE);
    
        }
    
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion,int newVersion) 
        {
            Log.w(TAG, "Upgrading database from version "+oldVersion+" to "+newVersion+", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS "+DATABASE_TABLE);
            onCreate(db);
        }
    }    
    
    //---opens the database---
    public DBAdapter open() throws SQLException 
    {
        db = DBHelper.getWritableDatabase();
        return this;
    }
    
    //---closes the database---    
    public void close() 
    {
        DBHelper.close();
    }
    
    //used to create the the new table
    public void createNewTable(String t_name){
        this.DATABASE_TABLE=t_name;
        db.execSQL(this.DATABASE_CREATE);
    }
    
    
    //---insert a title into the database---
    public long insertTitle(String isbn, String title, String word, String sound, String publisher) 
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_ISBN, isbn);
        initialValues.put(KEY_TITLE, title);
        initialValues.put(KEY_WORD, word);
        initialValues.put(KEY_SOUND, sound);
        initialValues.put(KEY_PUBLISHER, publisher);
        return db.insert(DATABASE_TABLE, null, initialValues);
    }
    
    //---deletes a particular title---
    public boolean deleteTitle(long rowId) 
    {
        return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
    }
    
    public boolean deleteAllTitle()
    {
        return db.delete(DATABASE_TABLE,null, null)>0;
    }
    public Cursor getAllTitles() 
    {
        Cursor mCursor = db.query(DATABASE_TABLE, new String[] {
                KEY_ROWID, 
                KEY_ISBN,
                KEY_TITLE,
                KEY_WORD,
                KEY_SOUND,
                KEY_PUBLISHER}, 
                null, 
                null, 
                null,
                null, 
                null,
                null);
    
        return mCursor;
    }
    
    
    //---retrieves a particular title---
    public Cursor getTitle(long rowId) throws SQLException 
    {
        Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {
                        KEY_ROWID,
                        KEY_ISBN, 
                        KEY_TITLE,
                        KEY_WORD,
                        KEY_SOUND,
                        KEY_PUBLISHER
                        }, 
                        KEY_ROWID + "=" + rowId, 
                        null,
                        null, 
                        null, 
                        null, ////////////////////////////
                        null);
        if (mCursor != null) 
        {
            mCursor.moveToFirst();
        }
        return mCursor;
    }
    // to fetch TextFile with Sound file
    public Cursor getSound(String str) throws SQLException
    {
        String file = Environment.getExternalStorageDirectory().getAbsolutePath();
        file = file+"/"+str+".3gp";
    
        Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {
                    KEY_ROWID,
                    KEY_ISBN, 
                    KEY_TITLE,
                    KEY_WORD,
                    KEY_SOUND,
                    KEY_PUBLISHER
                }, 
                KEY_SOUND + "=" +file, 
                null,
                null, 
                null, 
                null,
                null);
        if (mCursor != null) 
      { 
       mCursor.moveToFirst();
      }
     return mCursor;
    
    }
    
    public void deleteAll()
    {
        this.db.delete(DATABASE_TABLE, null, null);
    }
    
    //---updates a title---
    public boolean updateTitle(long rowId, String isbn, String title,String word,String sound, String publisher) 
    {
        ContentValues args = new ContentValues();
        args.put(KEY_ISBN, isbn);
        args.put(KEY_TITLE, title);
        args.put(KEY_WORD, word);
        args.put(KEY_SOUND, sound);
        args.put(KEY_PUBLISHER, publisher);
        return db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
    }
    

    }

    in your activity

    db.open();
          db.createNewTable("ur table name");
    

    this solve ur problem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting some very jerky scrolling while using the code below to create a
I'm writing a small database adapter in Python, mostly for fun. I'm trying to
I'm having to modify a lot of code to set a SqlCe database connection
I have made the following code to retrive data from SQLite database. public Cursor
I would like to use JRuby to run a script which populates a database.
I have a database like this: table pepak, table category, table subcategory I just
Database? Page variables? Enum? I'm looking for opinions here.
Database is OracleXE and here is the problem: data gets entered in tables UPS
Database: DB2 v9.5 on AIX Scenario: I have 2 instances- db2inst1 and db2inst2. I
Database setup (MySQL) table: top_fives id, uid, first, second, third, fourth, fifth, creation_date 1,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.