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
herahadi
Posts: 27
Registered: ‎02-20-2013
My Device: 9900
Accepted Solution

Inserting data into database java blackberry

here is my code to insert data into database

package mypackage;

import net.rim.device.api.database.Database;
import net.rim.device.api.database.DatabaseFactory;
import net.rim.device.api.database.Statement;
import net.rim.device.api.io.URI;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;

//class untuk insert data ke database table People

class InsertDataScreen extends MainScreen
{
    Database d;
    public InsertDataScreen()
    {
        LabelField title = new LabelField("SQLite Insert Data " +
                                          "Schema Sample", 
                                          LabelField.ELLIPSIS | 
                                          LabelField.USE_ALL_WIDTH);
        setTitle(title);
        add(new RichTextField("Attempting to insert data into " +
                               "MyTestDatabase.db on the SDCard."));
        try
        {
            URI myURI = URI.create("file:///Store/Databases/SQLite_Guide/" +
                                   "MyTestDatabase2.db"); 
            d = DatabaseFactory.open(myURI);
            
            Statement st = d.createStatement("INSERT INTO People(Name,Age) " +
                                             "VALUES ('John',37)");
            st.prepare();
            st.execute();
            st.close();
            d.close();
            add(new RichTextField("inserting data successful"));
            System.out.println( "inserting data successful" );
        }
        catch ( Exception e ) 
        {         
            System.out.println( e.getMessage() );
            e.printStackTrace();
        }
        
             
    }
}

i have checked that database is exist. when i run code above, my data was never inserted into database, code bellow

add(new RichTextField("inserting data successful"));

never called.

 

anyone know what is my wrong? please

Contributor
herahadi
Posts: 27
Registered: ‎02-20-2013
My Device: 9900

Re: Inserting data into database java blackberry

help me please, anyone.

Developer
peter_strange
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Inserting data into database java blackberry

When you step through this code in the debugger what happens?

Contributor
herahadi
Posts: 27
Registered: ‎02-20-2013
My Device: 9900

Re: Inserting data into database java blackberry

[ Edited ]

Problem solved!

 

i have successfully insert and view data on database when i change the storage location into SDCard

 

i dont know why, but its probably that blackberry can't save SQLite database on internal memory (OS7)