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
Kiran_Snist
Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified

Prob with insert statement in Sqlite!!!!!

[ Edited ]

I have been using sqlite for my project. I have created the database and table succesfully but when i insert values into the table i m thrown an Database exception in Statement.prepare() line, which is thrown when the database is closed, but that is'nt the case here.

 

Here is My table:

Statement st = fileDetails.createStatement( "CREATE TABLE 'GetFilelist'( " +              "'AutoID' TEXT, " +
			        "'PageName' TEXT" +
			        "'PageFullUrl' TEXT"+
			        "'PageLastUpdateDate' TEXT"+
			        "'VersionNo' TEXT )" );

 Here is my code to insert values into the table:

 

Statement st = fileDetails.createStatement("INSERT INTO GetFilelist(AutoID,PageName,PageFullUrl,PageLastUpdateDate,VersionNo)" +
                                       "VALUES ("+ "'"+tempAutoID+"',"+"'"+temppageName+"',"+"'"+tempPageFullUrl+"',"+"'"+tempPageLastUpdateDate+"',"+"'"+tempVersionNo+"')");

 where the temp values all are strings.

 

The above statement is throwing error when i prepare the statement using st.prepare();

 

Interesting thing  is when i repalce the above insert statement with the below code its working great:

 

Statement st1=fileDetails.createStatement("INSERT INTO GetFilelist(AutoID,PageName)"+
															"VALUES('temp1','temp2')");

 

so, i think there is something to do when u give the values in the insert statement at the run time as in the first insert statement.

 

Could sme1 help in this issue??

 

Thanz

Kiran

 

Developer
LoganSix
Posts: 265
Registered: ‎01-02-2011
My Device: Z30, PlayBook

Re: Prob with insert statement in Sqlite!!!!!

If you are using the SQLite Demo, it shows that you should open and close the database for each transaction.  This is not correct.  You should open the database when you first open the application and then close it when you leave the application.  Once you open the database, you should call that database instance each time for when you create the statements.

 

Using the SQLite Demo as a starting point.  I created a class called SQLManager were I initialize the database (appdB).  Then on the MainScreen, I pass that database into each call to the class that handles the table inserts, updates, etc. 

 

public SQLManager _sqlManager;

public SDAMainScreen(SQLManager sqlManager) { _sqlManager; _sqlManager = sqlManager; try {
            _sqlManager.initializeDatabase();
        
        } catch (DataTypeException e1) {
            e1.printStackTrace();
        }

try {
            MyTableClass.insert(Param1, Param2, _sqlManager.appDB);
        } catch (Exception e) {
            e.printStackTrace();
        }
}

 

This worked for me when I could get the inserts and selects to work with the simulator, but not on the device itself.

_________________
Meetup for BlackBerry 10
Meetup Search Tool - not available at the moment
Developer
Kiran_Snist
Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified

Re: Prob with insert statement in Sqlite!!!!!

The fact of the matter is that the "Create table" statement is incorrect.. I was misguided since the debugger showed error at insert statement... This is annoying... Neverthless this should be a lesson to learn... thnq guys....
Developer
LoganSix
Posts: 265
Registered: ‎01-02-2011
My Device: Z30, PlayBook

Re: Prob with insert statement in Sqlite!!!!!

If you don't have it alredy, you should get the SQLite Manager Add-on for FireFox. 

https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/

 

With that, you can test your SQLite create strings and even browse your database (local file or device) to see how the tables are created and the data that is inserted.  You can also modify the data as well.

_________________
Meetup for BlackBerry 10
Meetup Search Tool - not available at the moment