BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-27-2011, 07:39 AM   #1 (permalink)
New Member
 
Join Date: Aug 2011
Model: 8310
PIN: N/A
Carrier: Rogers
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
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 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
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 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
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 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
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


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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 10:29 AM
Passwords database File from magmic's password program barjohn General BlackBerry Discussion 0 10-02-2004 02:21 PM





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