Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Quick question about creating a database

  • 03-06-2012 12:54PM
    #1
    Registered Users, Registered Users 2 Posts: 5,949 ✭✭✭


    Hi, I'm creating my first java application - just messing around really. At what point is the database normally installed in an application - generally and in the case of a mobile application? Is it that during the application installation, extra code is run to create the database? Is there a good sample code for creating a database as I'm sure its fairly similiar for most simple applications? Thanks.


Comments

  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Hi, I'm creating my first java application - just messing around really.
    I presume you mean native Android development, when you say Java. The following is specific only to that.
    At what point is the database normally installed in an application - generally and in the case of a mobile application? Is it that during the application installation, extra code is run to create the database?
    Not on installation, but when the app is run - specifically that part of the app code which creates the database is executed (note that this will also trigger the onUpgrade method that is used for schema up/downgrades).
    Is there a good sample code for creating a database as I'm sure its fairly similiar for most simple applications? Thanks.
    http://www.vogella.com/articles/AndroidSQLite/article.html
    http://www.drdobbs.com/mobile/232900584


  • Registered Users, Registered Users 2 Posts: 5,949 ✭✭✭A Primal Nut


    Thanks; actually just doing a java program on Windows for now, but planning to start making it for Android as well so thats why I posted here.

    So basically, when the program is first opened, it checks to see if the database already exists, and if not, creates it.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Thanks; actually just doing a java program on Windows for now, but planning to start making it for Android as well so thats why I posted here.
    If you're doing this as a Java Windows application, then you be using a different library set, so a different process is involved.
    So basically, when the program is first opened, it checks to see if the database already exists, and if not, creates it.
    No, when the database is first opened, explicitly calling the getWritableDatabase method, this will trigger the SQLiteOpenHelper object's onCreate method to check if it exists, and if not, create it.


Advertisement