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: 34
Registered: ‎03-08-2012
My Device: Simulator
My Carrier: Developer
Accepted Solution

Deleting row from SQLite Database : Blackberry

I m using Table Adapter Screen to create a layout that show data from database in a tabular fashion.I added a button field to each row of layout to delete that particular row. Below i m attaching the code for deletion .It is showing Exception : SQL logic error or missing database. Is there any thing wrong with my Query??? There is no problem in database functions of creating,tables,insertion,retrival etc. Kindly help me out here. It gives error at .prepare(); statement.

i m passing the name in query , which is obtained from the selected row

 

public void deletetarget(String cname) {

        Statement deletetarget = null;

        try

        {
            URI myURI = URI.create("file:///store/home/Databases/SampleDatabase.db");

            d.close();
            d = DatabaseFactory.open(myURI);

    deletetarget = d.createStatement("DELETE  FROM targetCity WHERE KEY_CITYNAME         ='"+cname+"'");

            deletetarget.prepare();

                deletetarget.execute();
            deletetarget.close();
            d.close();  
        }

        catch ( Exception e ) 

        {         

            System.out.println("Delete Statement Exception "+e);
            e.printStackTrace();
        }
    }

 


Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: Deleting row from SQLite Database : Blackberry

try this

 

"DELETE  FROM targetCity WHERE KEY_CITYNAME ='+cname+'");
Developer
Posts: 34
Registered: ‎03-08-2012
My Device: Simulator
My Carrier: Developer

Re: Deleting row from SQLite Database : Blackberry

@rabiray.....i m passing a variable which gives the string value........i m not passing a string directly......
Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: Deleting row from SQLite Database : Blackberry

applogies...

 

I cant see any error in ur query....i hope u have tried the query in sqlite browser...with a constant value

New Developer
Posts: 53
Registered: ‎06-07-2011
My Device: 9800 torch
My Carrier: o2

Re: Deleting row from SQLite Database : Blackberry

should it not be

DELETE * FROM targetCity WHERE KEY_CITYNAME='" + cname + "'"

 

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: Deleting row from SQLite Database : Blackberry

[ Edited ]

try

 

"DELETE  FROM targetCity WHERE KEY_CITYNAME IN ( ' " +cname+ " ' ) "

Developer
Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified

Re: Deleting row from SQLite Database : Blackberry

This should do...

Statement st=cardDetails.createStatement("DELETE FROM Temp where temp1=?");
				st.prepare();
				
				
				st.bind(1,var_temp1);
				st.execute();
				st.close();

 

Developer
Posts: 34
Registered: ‎03-08-2012
My Device: Simulator
My Carrier: Developer

Re: Deleting row from SQLite Database : Blackberry

there is nothing wrong in the Query..............................any way it was solved by......writing database.close() method on the top of the URI field

Developer
Posts: 34
Registered: ‎03-08-2012
My Device: Simulator
My Carrier: Developer

Re: Deleting row from SQLite Database : Blackberry

thanks every one for giving ur time and efforts.....thanks again....