0
votes

I have assigned key to every entity in my Data store. but when i click on delete , i am not able to delete it ..Please help me regarding that.

I have created a function "deleteuser()" inside my SAFCServlet.java class , which i am trying to invoke when trying to delete .My function is :

SAFCServlet.java
.............

public static void deleteuser(string name)
   {
    Key UserKey = KeyFactory.createKey("safc",name );
       System.out.println("the value od userkey is" +UserKey);
    ds.delete(UserKey);



   }

above function i am calling from Delete.java Servlet

Delete.java
..................

String key1=req.getParameter("key").toString();
PrintWriter out = resp.getWriter();
out.println("I m in delete");
System.out.println("the first key is "+key1);
SAFCServlet.deleteuser(key1);

The above Servlet "Delete.java" gets called when i click on delete,but i am not able to delete .please help me with that.The "key1" in above function is the key (this key is usergenerated not the inbuilt key of data store) of every entry in my datastore

MY TABLE IS .For Example:

KIND is "safc" (means Table name)

key|Title(data)|Author

78 |john |laxmi

99 |Andy |ashish

We can create any entity like this in datastore :

     Entity e = new Entity("safc");
     e.setParameter("username");
     e.setParameter("password"); 
     e.setParameter("Key"); 
     ds.put(e);

While trying to delete from datastore i am getting error in my code and i am not able to resolve it.code i used is shown above in" Delete.java" servlet and "SAFCServlet.java" , i found this somewhere and i was trying to implement it.

2
How do you create entities?Andrei Volgin
When you say you are "not able to delete", what do you mean ? Do you get an error message or is there nothing happening ?brian
Hi , i have updated my question above .please see thatGiggleGirl
@brian not able to delete ,m getting NullPointerException little worried.GiggleGirl

2 Answers

0
votes

you are missing the datastore API initialization in deleteuser() function

Try this

Delete.java

   String key1=req.getParameter("key").toString();
   PrintWriter out = resp.getWriter();
   out.println("I m in delete");
   System.out.println("the first key is "+key1);

   Datastore ds= DatastoreServiceFactory.getDatastoreService();
   Key UserKey = KeyFactory.createKey("safc",key1 );
   System.out.println("the value od userkey is" +UserKey);
   ds.delete(UserKey);
0
votes
String key1=req.getParameter("key");

Datastore ds= DatastoreServiceFactory.getDatastoreService();
Key UserKey = KeyFactory.createKey("safc",key1 ); // Key key = KeyFactory.createKey("KIND",ID);
ds.delete(UserKey); //delete(key)