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
Developer
Posts: 90
Registered: ‎06-04-2010
My Device: Blackberry 9630
My Carrier: verizon
Accepted Solution

SQL -Lite Create Table?

I'm wanting to save a string of text into a sql-lite database that is called "message1."  I press the save button to invoke this code in my listener. 

 

URI myURI = URI.create("file:///SDCard/flash.db"); 
DatabaseFactory.open(myURI);    	
Statement st = d.createStatement( "CREATE TABLE Restaurant (Experience TEXT)" );   
Dialog.alert("Here1!"); 	
st.prepare();
st.execute();
st.close();  
    				
Statement st1 = d.createStatement("INSERT INTO Restaurant(Experience) VALUES ('message1')");    					 
st1.prepare(); 
st1.execute(); 
st1.close(); 
d.close();    					 
Dialog.alert("Your info was saved!"); 

 I cant even get my Dialog statement to appear?  I must be doing something wrong in the line where I create the table?

Statement st = d.createStatement( "CREATE TABLE Restaurant (Experience TEXT)" );  

 

Because when I move the dialog statement before this line...I can see the Dialog Box

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: SQL -Lite Create Table?

 

Database d;
URI myURI = URI.create("file:///SDCard/flash.db");
d = DatabaseFactory.open(myURI);
Statement st = d.createStatement( "CREATE TABLE Restaurant (Experience TEXT)" );
Dialog.alert("Here1!");
st.prepare();
st.execute();
st.close();

Statement st1 = d.createStatement("INSERT INTO Restaurant(Experience) VALUES ('message1')");
st1.prepare();
st1.execute();
st1.close();
d.close();
Dialog.alert("Your info was saved!");

I edited in your code, You were missing Somthing.

------------------------------------------------------------------------------------
Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.

 

 

Highlighted
Contributor
Posts: 26
Registered: ‎11-30-2010
My Device: Not Specified

Re: SQL -Lite Create Table?

 

Database db;
URI myURI = URI.create("file:///SDCard/flash.db"); 
db = DatabaseFactory.open(myURI);

Statement st= db.createStatement("CREATE TABLE 'Restaurant' ( "
					+ "'Experience' TEXT)");
			st.prepare();
			st.execute();
			st.close();
			
			Statement st1 = db.createStatement("INSERT INTO Restaurant(Experience) VALUES ('Message1')");
			st1.prepare();
			st1.execute();

db.close();

 I checked this code and its working fine.

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.

 

Developer
Posts: 90
Registered: ‎06-04-2010
My Device: Blackberry 9630
My Carrier: verizon

Re: SQL -Lite Create Table?

Yes I found the error, I was not creating the Database properly.

 

Thank you for all your help with my numerous problems!!

 

Scientific