BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 08-27-2011, 07:39 AM   #1
salassi
New Member
 
Join Date: Aug 2011
Model: 8310
PIN: N/A
Carrier: Rogers
Posts: 12
Angry Database File Not Been Created

Please Login to Remove!

This is a program to create a database in SQLite...I've created a folder in E:/TestProject....I've set this path to simulator/memory/PC file system for SDCard Files/

But my database doesn't seem to be created in SQLite......

Can any1 tell me where i went wrong?





xxx91;codexxx93;
package database;

import net.rim.device.api.ui.container.MainScreen;
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.Graphics;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
public class firstprogramscreen extends MainScreen
{
Database d;
public firstprogramscreen()
{

LabelField title = new LabelField("SQLite Create Database Sample",
LabelField.ELLIPSIS |
LabelField.USE_ALL_WIDTH);
setTitle(title);

EditField ed = new EditField()
{
protected void paint(Graphics graphics)
{
// TODO Auto-generated method stub
super.paint(graphics);
}
};
add(new RichTextField("Creating a Table called "));
try
{
URI myURI = URI.create("file:///SDCard/Databases/SQLite_Guide/DatabaseSample.db");
d = DatabaseFactory.openOrCreate(myURI);
Statement st = d.createStatement( "CREATE TABLE 'People' ( " +
"'Name' TEXT, " +
"'Age' INTEGER )" );
st.prepare();
st.execute();
st.close();
d.close();
}
catch ( Exception e )
{
System.out.println( e.getMessage() );
e.printStackTrace();
}
}

}

xxx91;/codexxx93;

Desparately waiting for the answer


Thanks in advance

Last edited by salassi; 08-27-2011 at 07:44 AM.. Reason: the code is not formatted
Offline  
Old 08-27-2011, 10:45 AM   #2
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default Re: Database File Not Been Created

Something happened to the sticky thread. All you need to do is click the php icon on the far righe to the toolbar and paste your code in between the PHP tags.

PHP Code:
import net.rim.device.api.ui.container.MainScreen;
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.Graphics;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
public class 
firstprogramscreen extends MainScreen
{
  
Database d;
  public 
firstprogramscreen()
  {

    
LabelField title = new LabelField("SQLite Create Database Sample",
    
LabelField.ELLIPSIS |
    
LabelField.USE_ALL_WIDTH);
    
setTitle(title);

    
EditField ed = new EditField()
    {
       protected 
void paint(Graphics graphics)
       {
          
// TODO Auto-generated method stub
          
super.paint(graphics);
       }
    };
    
add(new RichTextField("Creating a Table called "));
    try
    {
      
URI myURI URI.create("file:///SDCard/Databases/SQLite_Guide/DatabaseSample.db");
      
DatabaseFactory.openOrCreate(myURI);
      
Statement st d.createStatement"CREATE TABLE 'People' ( " +
      
"'Name' TEXT, " +
      
"'Age' INTEGER )" );
      
st.prepare();
      
st.execute();
      
st.close();
      
d.close();
    }
    catch ( 
Exception e )
    {
      
System.out.printlne.getMessage() );
      
e.printStackTrace();
    }
  }


This makes it much easier to look at the code.
__________________
My other Blackberry is a PlayBook.

Last edited by hrbuckley; 08-27-2011 at 11:03 AM..
Offline  
Old 08-27-2011, 10:50 AM   #3
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Default Re: Database File Not Been Created

I don't like the space in your URI:

URI myURI = URI.create("file:///SDCard/Databases/SQLite_Guide /DatabaseSample.db");

Are you catching an exception?


Edit: never mind - there isn't a space there - just looks like it from the formatting.
Offline  
Old 08-27-2011, 11:18 AM   #4
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default Re: Database File Not Been Created

I created the following program based on the sample from the API documentation and your code;

PHP Code:
import javax.microedition.io.file.FileSystemRegistry;
import java.util.Enumeration;
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.system.Application;
 
public class 
AddDatabaseTable extends Application 
{
    public static 
void main(Stringxxx91;xxx93; args)
    {
        
AddDatabaseTable app = new AddDatabaseTable();
        try
        {
            
Enumeration en FileSystemRegistry.listRoots();
            while (
en.hasMoreElements()) {
                
System.out.println(en.nextElement());
            }
        
            
//URI myURI = URI.create("/SDCard/test.db"); 
            
URI myURI URI.create("/SDCard/Databases/SQLite_Guide/DatabaseSample.db");
            
            
Database d DatabaseFactory.openOrCreate(myURI);
            
Statement st d.createStatement"CREATE TABLE 'People' ( "+"'Name' TEXT, " "'Age' INTEGER )" );
            
st.prepare();
            
st.execute();
            
st.close();
        }
        catch ( 
Exception e 
        {         
            
System.out.printlne.getMessage() );
        }
    }

The file is created in the simulated SDCard, but only if it is mounted. When you run your code do you get an exception? If so what is exceptiion and message? Try using the FileSystemRegistry fragment to ensure that you actually have the file system you want to create the DB on. You will want to do this for any final code anyway.
__________________
My other Blackberry is a PlayBook.
Offline  
Old 08-27-2011, 11:26 AM   #5
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default Re: Database File Not Been Created

Quote:
Originally Posted by Dougsg38p View Post
I don't like the space in your URI:

URI myURI = URI.create("file:///SDCard/Databases/SQLite_Guide /DatabaseSample.db");

Are you catching an exception?


Edit: never mind - there isn't a space there - just looks like it from the formatting.
Yah, that slipped by me when I was reformatting the code.
__________________
My other Blackberry is a PlayBook.
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads for: Database File Not Been Created
Thread Thread Starter Forum Replies Last Post
How to Animate Themes Sy4 BlackBerry Themes 85 09-03-2011 12:24 AM
Which to download bby31288 General 8100 Series Discussion - Pearl 2 10-03-2008 06:51 AM
BES for Exchange 4.0.4 Available Now BlackBerryLinks BES Admin Corner 28 05-06-2006 10:38 AM
BES for Domino 4.0 SP4 - Coming Soon jibi BES Admin Corner 0 03-01-2006 11:29 AM
Passwords database File from magmic's password program barjohn General BlackBerry Discussion 0 10-02-2004 02:21 PM


Lot of 2 IBM Correctable Ribbon Cassette Black 1299300 NOS Original OEM picture

Lot of 2 IBM Correctable Ribbon Cassette Black 1299300 NOS Original OEM

$12.00



IBM CASH DRAWER LOCK #9960 SET OF 2 KEYS. AFTERMARKET KEY'S SAME AS OEM 33G3360 picture

IBM CASH DRAWER LOCK #9960 SET OF 2 KEYS. AFTERMARKET KEY'S SAME AS OEM 33G3360

$22.00



New 2 Sets of 2 (4) keys total OEM 9952 IBM Keys for Cash Drawers Displays Locks picture

New 2 Sets of 2 (4) keys total OEM 9952 IBM Keys for Cash Drawers Displays Locks

$14.99



IBM CASH DRAWER KEY'S #9952 SET OF 2 KEYS. AFTERMARKET KEY'S SAME AS OEM 33G3352 picture

IBM CASH DRAWER KEY'S #9952 SET OF 2 KEYS. AFTERMARKET KEY'S SAME AS OEM 33G3352

$18.00



OEM  IBM Type 5441 WheelWriter 3 1356658 1362400-02 Main Boards Tested Working picture

OEM IBM Type 5441 WheelWriter 3 1356658 1362400-02 Main Boards Tested Working

$49.99



IBM Genuine OEM Printer Filler Wide Credit Card Holder 10N1259 picture

IBM Genuine OEM Printer Filler Wide Credit Card Holder 10N1259

$24.79







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.