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
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

databaseException problem

i'm fetching data from database ,but during fetching  that will gives me the following error

 heeerrrror==net.rim.device.api.database.DatabaseException: SELECT * FROM tbfavthought WHERE fav='Don[0.0] 't have too many desires. Less luggage, more comfort makes travel a pleasure.': SQL logic error or m[0.0] issing database

 

Please use plain text.
Developer
simon_hain
Posts: 15,869
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: databaseException problem

my guess would be that the ' causes the issue, you have to escape it. i suggest to use prepared statements to avoid issues like this.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: databaseException problem

i'm new to database , can u suggest me or what is the statement to avoid this issue..?
as u can see i have used this SELECT * FROM tbfavthought WHERE fav=' '
Please use plain text.
Developer
simon_hain
Posts: 15,869
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: databaseException problem

the inverted comma is used as a special character in sql, as you should be aware of.
it can also be contained in the content you want to save though, so you have to escape it.
(read about sql injection, little bobby drop tables etc if you want to know more)

if you read the documentation, for example http://docs.blackberry.com/en/developers/deliverables/17952/Working_with_SQLite_databases_1219779_11... you see that prepared statements are suggested.

http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/database/Statement.html also explains how to use prepared statements.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: databaseException problem

and what about statement.bind(" "," ");
can i implement that..?
Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: databaseException problem

still, not able to solve the issue, simon_hain, you told me ' it can also be contained in the content you want to save though, so you have to escape it.' how can i escape it, i did not understand properly, plz guide me
Please use plain text.
Developer
simon_hain
Posts: 15,869
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: databaseException problem

it is automatically escaped if you use bind with prepared statements.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Regular Contributor
meghana_datar
Posts: 56
Registered: ‎11-24-2010
My Device: Not Specified

Re: databaseException problem

Just one question : Is your database created properly. DatabaseException can be because of Incorrect DB path, Unable to open database as it may have not being close somewhere ie IO exception. 

 

Please check with your create and open database statement once. As the Query looks fine. :smileyhappy:

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: databaseException problem

i never used bind , plz can u explain me.

i have string str= "

"Don 't have too many desires. Less luggage, more comfort makes travel a pleasure.";

i have to insert this  into table how can i use bind with prepared statement.

Please use plain text.
Developer
simon_hain
Posts: 15,869
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: databaseException problem

if you would read the link i posted: it has quite some code samples.
like
http://docs.blackberry.com/en/developers/deliverables/17952/CS_inserting_table_data_1222419_11.jsp
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.