Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 49
Registered: ‎12-21-2010
My Device: 9000 Bold Device
My Carrier: software developer

Re: Sqlite issue

hi,

here is my full code

 

public class InsertDataInTable extends MainScreen{
    public Database sqliteDB;
    public InsertDataInTable() {
        LabelField title = new LabelField("Create DB Application",
                LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
            setTitle(title);
            
            add(new RichTextField("Initializing db create process..."));
            try{
                URI myURI = URI.create("file:///store/Databases/database.db");
                sqliteDB = DatabaseFactory.open(myURI);

                Statement st = sqliteDB.createStatement("INSERT INTO Employee(Name,Age) " +
                        "VALUES ('Ralph',47)");
                st.prepare();
                st.execute();

                add(new RichTextField(
                    "Status: Data is successfully inserted."));
            } catch (Exception e){
                System.out.println(e.getMessage());
                add(new RichTextField(
                    "Status: Data is not inserted Successfully."));
                add(new RichTextField(e.getMessage()));
                e.printStackTrace();
            }
    }

 Thanks

Developer
Posts: 231
Registered: ‎03-16-2011
My Device: 9700, 9550, and JDE
My Carrier: AIRTEL, BSNL

Re: Sqlite issue

ok........... uve created seperated class , gud.

 

now check ::

explore the file system to check if file is created

if u run db create  command then it should run with no exception

also make sure the same for create table

if both run successfully only then insert will run

 

also remember to close the db statement & db connection in all class

then try it


available on: Monday to Friday, Indian standard (day) time : )
  • Give kudos by clicking on the star icon to say "Thanks!" if you feel this response is helpful.
  • Click "Accept as Solution" if this post was what you needed. so that people who are trying to help will not waste their time reading a thread where no help is needed.

Contributor
Posts: 49
Registered: ‎12-21-2010
My Device: 9000 Bold Device
My Carrier: software developer

Re: Sqlite issue

hi,

 

The user can see only first time all functionality like create table, insert and selected data from database.if she/he wants to see onceagain then

1.the database is created Successfully

2.table is not created CREATE TABLE 'Employee' ( " +"'Name' TEXT, " + "'Age' INTEGER )Smiley FrustratedQL logic error

or database missing

3.data is not inserted file system error(12)

4.data is not selected file system error(12)

 

why it is showing exception.please tell me what is the issue behind it.

Thanks

 

Developer
Posts: 231
Registered: ‎03-16-2011
My Device: 9700, 9550, and JDE
My Carrier: AIRTEL, BSNL

Re: Sqlite issue

problem in table creation................. check its logic, or paste it here


available on: Monday to Friday, Indian standard (day) time : )
  • Give kudos by clicking on the star icon to say "Thanks!" if you feel this response is helpful.
  • Click "Accept as Solution" if this post was what you needed. so that people who are trying to help will not waste their time reading a thread where no help is needed.

Contributor
Posts: 49
Registered: ‎12-21-2010
My Device: 9000 Bold Device
My Carrier: software developer

Re: Sqlite issue

hi,

 i have created separate class,here is my code

 

public class CreateTableDemo extends MainScreen{
    public Database sqliteDB;
    public CreateTableDemo() {
        LabelField title = new LabelField("Create DB Application",
                LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
            setTitle(title);
            
            add(new RichTextField("Initializing db create process..."));
            try{
                URI myURI = URI.create("file:///store/Databases/database.db");
                sqliteDB = DatabaseFactory.openOrCreate(myURI);

                Statement st = sqliteDB.createStatement( "CREATE TABLE 'Employee' ( " +"'Name' TEXT, " + "'Age' INTEGER )" );

                st.prepare();
                st.execute();
                st.close();
                sqliteDB.close();
                add(new RichTextField(
                    "Status: Table was successfully created."));
                
            } catch (Exception e){
                System.out.println(e.getMessage());
                add(new RichTextField(
                    "Status: Table was not created."));
                add(new RichTextField(e.getMessage()));
                e.printStackTrace();
            }

      }

}

Thanks

Developer
Posts: 231
Registered: ‎03-16-2011
My Device: 9700, 9550, and JDE
My Carrier: AIRTEL, BSNL

Re: Sqlite issue

remove the line

e.printStackTrace();

 

 

and make sure create statement never execute more than once !


available on: Monday to Friday, Indian standard (day) time : )
  • Give kudos by clicking on the star icon to say "Thanks!" if you feel this response is helpful.
  • Click "Accept as Solution" if this post was what you needed. so that people who are trying to help will not waste their time reading a thread where no help is needed.

Contributor
Posts: 49
Registered: ‎12-21-2010
My Device: 9000 Bold Device
My Carrier: software developer

Re: Sqlite issue

hi,

 

1. I have removed the line

e.printStackTrace();        but no difference, i am getting the same errors.

 

2. i want to update or download latest content of java, if u have any idea about any site, then please let me know.

 

Thanks a lot.

Developer
Posts: 231
Registered: ‎03-16-2011
My Device: 9700, 9550, and JDE
My Carrier: AIRTEL, BSNL

Re: Sqlite issue

oh man, the same code is running fine on my ide, and shoing table created successfully !

 

just comment out create table related queries, and try again..................


available on: Monday to Friday, Indian standard (day) time : )
  • Give kudos by clicking on the star icon to say "Thanks!" if you feel this response is helpful.
  • Click "Accept as Solution" if this post was what you needed. so that people who are trying to help will not waste their time reading a thread where no help is needed.

Contributor
Posts: 49
Registered: ‎12-21-2010
My Device: 9000 Bold Device
My Carrier: software developer

Re: Sqlite issue

hi,

 

Thanks a lot.its working fine

 

Thanks

Developer
Posts: 231
Registered: ‎03-16-2011
My Device: 9700, 9550, and JDE
My Carrier: AIRTEL, BSNL

Re: Sqlite issue

u can tick it as solved also Smiley Happy


available on: Monday to Friday, Indian standard (day) time : )
  • Give kudos by clicking on the star icon to say "Thanks!" if you feel this response is helpful.
  • Click "Accept as Solution" if this post was what you needed. so that people who are trying to help will not waste their time reading a thread where no help is needed.