0

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.

    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();
        }
    }
optimus
  • 1
  • 1

1 Answers1

1

Close your database before creating URI.

Change your query write like this ...

deletetarget = d.createStatement("DELETE  FROM targetCity WHERE KEY_CITYNAME = '"+cname+"'");
BBdev
  • 4,898
  • 2
  • 31
  • 45
  • BBdev....there is no difference in my code as compared to ur reply.....the space in the query is just because i have written the code in next line while pasting it here......its written correctly in plug in. – optimus May 22 '12 at 06:26
  • okkk then before creating your uri check if there is database closed or not if not then close it. And then try to create URI and all. i have updated the answer . – BBdev May 22 '12 at 06:45
  • i m already doing that..............the error occurs while prepare () method is calld – optimus May 22 '12 at 06:52
  • As i see ur code i am seeing that you are closing the database after creating URI so close the database before creating your URI then try to open you database. – BBdev May 22 '12 at 06:58
  • Is it because i m passing cname variable into the query?????....because if i directly pass the name it works fine.... – optimus May 22 '12 at 07:42
  • may be the value you are passing is null?? may be i am not sure so check the value before passing it in the method. – BBdev May 22 '12 at 07:50
  • i m checking it by putting print statement...let me show u the whole print statement that is showing error............................... – optimus May 22 '12 at 08:54
  • i m checking it by putting print statement...let me show u the whole print statement that is showing error............................... Delete Statement Exception ....net.rim.device.api.database.DatabaseException: DELETE FROM targetCity WHERE KEY_ID = 'Darwin'): SQL logic error or missing database.....here darwin is the name of the city to be passed – optimus May 22 '12 at 09:06
  • i just restarted eclipse and put d.close() above URI – optimus May 23 '12 at 04:42
  • that is what i was telling you from the first time you didnt noticed. i was always telling you that close the database before creating URI. So do you think it helped you then accept the answer. by doing so you will help other folks they will know what is the possible answer. – BBdev May 23 '12 at 05:09
  • yes but now it is working even when i donot put databse.close() method above URI........lets say it worked that way also ......so thanks for ur help BBDev.. – optimus May 23 '12 at 07:20