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 6675609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:52:41+00:00 2026-05-26T03:52:41+00:00

In the first time I have created one Table DEPTS . After that I

  • 0

In the first time I have created one Table DEPTS. After that I want to create another two tables FEEDS and ARTICLES.

But I see that the commends for creating new tables never executed, why?

Here is my code:

package com.android.database;

// ... imports ...

public class DatabaseHelper extends SQLiteOpenHelper{

static final String dbName = "appDB";
static int dbVersion = 3;
private static final String DEBPT_TABLE = "Dept";
private static final String COL_DEPT_ID = "DeptID";
private static final String COL_DEPT_NAME = "DeptName";
private static final String COL_DEPT_LAT = "DeptLat";
private static final String COL_DEPT_LNG = "DeptLng";

private static final String FEEDS_TABLE = "feeds";
private static final String COL_FEED_ID = "feed_id";
private static final String COL_FEED_TITLE = "title";
private static final String COL_FEED_URL = "url";

private static final String ARTICLES_TABLE = "articles";
private static final String COL_ARTICLE_ID = "article_id";
private static final String COL_ARTICLE_FEED_ID = "feed_id";
private static final String COL_ATRICLE_TITLE = "title";
private static final String COL_ATRICLE_URL = "url";

    public DatabaseHelper(Context context) {
        super(context, dbName, null, dbVersion);
        // TODO Auto-generated constructor stub
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        /*onCreate(SQLiteDatabase db): invoked when the database is created, 
        this is where we can create tables and columns to them, create views or triggers. */

        db.execSQL("CREATE TABLE "+DEBPT_TABLE+
                "("+COL_DEPT_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
                COL_DEPT_NAME+" TEXT NOT NULL, "+
                COL_DEPT_LAT+" REAL NOT NULL, "+
                COL_DEPT_LNG+" REAL NOT NULL);");

        db.execSQL("CREATE TABLE "+ FEEDS_TABLE+
                " ("+COL_FEED_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
                COL_FEED_TITLE +" TEXT NOT NULL,"+
                COL_FEED_URL+" TEXT_NOT_NULL);");

        db.execSQL("CREATE TABLE "+ ARTICLES_TABLE+
                " ("+COL_ARTICLE_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
                COL_ARTICLE_FEED_ID+ " INTEGER NOT NULL, "+
                COL_ATRICLE_TITLE+" TEXT NOT NULL, "+
                COL_ATRICLE_URL+" TEXT NOT NULL);");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        /*onUpgrade(SQLiteDatabse db, int oldVersion, int newVersion): invoked when we make a modification to 
        the database such as altering, dropping , creating new tables. */

        db.execSQL("DROP TABLE IF EXISTS "+DEBPT_TABLE);
        db.execSQL("DROP TABLE IF EXISTS "+FEEDS_TABLE);
        db.execSQL("DROP TABLE IF EXISTS "+ARTICLES_TABLE);
        onCreate(db);
    }

    public boolean insertDept(Department dept){
        SQLiteDatabase db = this.getReadableDatabase();// open database for read/write
        ContentValues cv = new ContentValues();
        cv.put(COL_DEPT_NAME, dept.getName());
        cv.put(COL_DEPT_LAT, dept.getLat());
        cv.put(COL_DEPT_LNG, dept.getLng());

        long result = db.insert(DEBPT_TABLE, COL_DEPT_ID, cv);
        // result : the row ID of the newly inserted row, or -1 if an error occurred 
        db.close();
        return (result>0);
    }

    public boolean updateDept(Department dept){
        SQLiteDatabase db = this.getReadableDatabase();
        ContentValues cv = new ContentValues();
        cv.put(COL_DEPT_NAME, dept.getName());
        cv.put(COL_DEPT_LAT, dept.getLat());
        cv.put(COL_DEPT_LNG, dept.getLng());

        int result = db.update(DEBPT_TABLE, cv,COL_DEPT_ID+"=?", new String []{String.valueOf(dept.getID())});
        //String[] args: The arguments of the WHERE clause
        db.close();
        return (result>0);
    }

    public boolean deleteDept(Department dept){
        SQLiteDatabase db = this.getWritableDatabase();
        int re = db.delete(DEBPT_TABLE, COL_DEPT_ID+"=?", new String[]{String.valueOf(dept.getID())});
        db.close();
        return (re>0);
    }

    public ArrayList<Department> getAllDepts(){
        ArrayList<Department> depts = new ArrayList<Department>();
        Department dept = null;
        SQLiteDatabase db = this.getWritableDatabase();

        Cursor cur = db.rawQuery("SELECT "+COL_DEPT_ID+ " as _id,"+
                COL_DEPT_NAME+", "+COL_DEPT_LAT+", "+COL_DEPT_LNG+" from "+DEBPT_TABLE,
                new String[]{});
        cur.moveToFirst();
        while(cur.moveToNext()){
            dept = new Department();
            dept.setID(cur.getInt(cur.getColumnIndex("_id")));
            dept.setName(cur.getString(cur.getColumnIndex(COL_DEPT_NAME)));
            dept.setLat(cur.getDouble(cur.getColumnIndex(COL_DEPT_LAT)));
            dept.setLat(cur.getDouble(cur.getColumnIndex(COL_DEPT_LNG)));

            depts.add(dept);
        }
        db.close();
        return depts;
    }

    public int GetDeptID(String Dept)
  {
   SQLiteDatabase db=this.getReadableDatabase();
   Cursor c=db.query(DEBPT_TABLE, new String[]{COL_DEPT_ID+" as _id",COL_DEPT_NAME},
    COL_DEPT_NAME+"=?", new String[]{Dept}, null, null, null);
   //Cursor c=db.rawQuery("SELECT "+COL_DEPT_ID+" as _id FROM "+DEBPT_TABLE+" 
   //WHERE "+COL_DEPT_NAME+"=?", new String []{Dept});
   c.moveToFirst();
   return c.getInt(c.getColumnIndex("_id"));  
  }

    public boolean insertFeed(String title, URL url) {
        SQLiteDatabase db=this.getReadableDatabase();
        ContentValues values = new ContentValues();
        values.put(COL_FEED_TITLE, title);
        values.put(COL_FEED_URL, url.toString());
        return (db.insert(FEEDS_TABLE, null, values) > 0);
    }

    public boolean deleteFeed(Feed feed) {
        SQLiteDatabase db=this.getReadableDatabase();
        return (db.delete(FEEDS_TABLE, COL_FEED_ID+ "=" + feed.feedId, null) > 0);
}

    public ArrayList<Feed> getFeeds() {
        SQLiteDatabase db=this.getReadableDatabase();
        ArrayList<Feed> feeds = new ArrayList<Feed>();
        try {
                Cursor c = db.query(FEEDS_TABLE, new String[] { COL_FEED_ID, COL_FEED_TITLE,
                        COL_FEED_URL }, null, null, null, null, null);

                int numRows = c.getCount();
                c.moveToFirst();
                for (int i = 0; i < numRows; ++i) {
                        Feed feed = new Feed();
                        feed.feedId = c.getLong(0);
                        feed.title = c.getString(1);
                        feed.url = new URL(c.getString(2));
                        feeds.add(feed);
                        c.moveToNext();
                }
        } catch (SQLException e) {
                Log.e("FEEDS DB", e.toString());
        } catch (MalformedURLException e) {
                Log.e("FEEDS DB", e.toString());
        }
        return feeds;
}

    public boolean insertArticle(Long feedId, String title, URL url) {
        SQLiteDatabase db=this.getReadableDatabase();
        ContentValues values = new ContentValues();
        values.put(COL_ARTICLE_FEED_ID, feedId);
        values.put(COL_ATRICLE_TITLE, title);
        values.put(COL_ATRICLE_URL, url.toString());
        return (db.insert(ARTICLES_TABLE, null, values) > 0);
        }

    public boolean deleteAricles(Long feedId) {
        SQLiteDatabase db=this.getReadableDatabase();
        return (db.delete(ARTICLES_TABLE, COL_ARTICLE_FEED_ID+"=" + feedId.toString(), null) > 0);
}

    public List<Article> getArticles(Long feedId) {
        SQLiteDatabase db=this.getReadableDatabase();
        ArrayList<Article> articles = new ArrayList<Article>();
        try {
                Cursor c = db.query(ARTICLES_TABLE, new String[] { "article_id",
                                "feed_id", "title", "url" },
                                "feed_id=" + feedId.toString(), null, null, null, null);

                int numRows = c.getCount();
                c.moveToFirst();
                for (int i = 0; i < numRows; ++i) {
                        Article article = new Article();
                        article.articleId = c.getLong(0);
                        article.feedId = c.getLong(1);
                        article.title = c.getString(2);
                        article.url = new URL(c.getString(3));
                        articles.add(article);
                        c.moveToNext();
                }
        } catch (SQLException e) {
                Log.e("ARTICLES DB", e.toString());
        } catch (MalformedURLException e) {
                Log.e("ARTICLES DB", e.toString());
        }
        return articles;
}

}
  • 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-26T03:52:42+00:00Added an answer on May 26, 2026 at 3:52 am

    You dont pass the version number in here

    public DatabaseHelper(Context context) {
    
            super(context, dbName, null, dbVersion);
    
            // TODO Auto-generated constructor stub
    
        }
    

    Should be like this

      public DatabaseHelper(Context context, String dbName, null, int dbVersion) 
    {
    
            super(context, dbName, null, dbVersion);
    
            // TODO Auto-generated constructor stub
    
        }
    

    Dont forget to update your version number

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

Sidebar

Related Questions

i have a table that have one column (AbsoluteUrl NVARCHAR(2048)) and i want to
I want to have one table with two TIMESTAMP columns. One column to keep
I have created one database and one table user in that while running my
first time use JTree. Just wondering is it possible to have more than one
I have 2 macros below that I am trying to execute 1 after another
I have created the following tables in SQLite3 to tag items (after reading this
So I have a typed dataset that I have created records for from another
I have two tables user (one) and transaction (many) and I need to get
This is the first time I have manipulated hashes and arrays in this way
I have just installed C# for the first time, and at first glance it

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.