lundi 26 avril 2021

Old error message wont go away Eclipe - Tomcat

I am trying to implement simple rest-ful web-sevice where i get book number from url and embed book name in a json object. I followed a tutorial. It is working fine. So i furthered my work by adding data access stuff to retrieve credentials from data base and add to json object. The moment i ran service it gave me a couple of messages. i removed the code (data access), stopped tomcat, cleaned, re-built project and restarted tomcat. cleared history of chrome. but no matter what, service wont go in the previous state. Here initial class file (snippet 1):-

 package book;
//annotations
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.apache.tomcat.util.codec.binary.Base64;
import org.json.simple.JSONObject;
@Path("/number")
public class bnumber {
@GET
@Produces("application/json")
@Path("{booknumber}")
   //  public JSONObject numberinfo(@PathParam("booknumber") int bnumb) {       
JSONObject obj = new JSONObject();
String bname = "test book";
obj.put("name", bname);
obj.put("bookid", bnumb);
return obj;
}
}

the url that i use

   localhost:8080/WS/number/1234

i get output

    {name,test book; bookid,1234}

Now i added persistance to get data from db i recieved a myriad of errors (snippet 2):-

package book;
//annotations
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.apache.tomcat.util.codec.binary.Base64;
import org.json.simple.JSONObject;
@Path("/number")
public class bnumber {
@GET
@Produces("application/json")
@Path("{booknumber}")
   //  public JSONObject numberinfo(@PathParam("booknumber") int bnumb) {       
JSONObject obj = new JSONObject();
String bname = "test book";
//............data from db...............
List booklist = new ArrayList();
Session session = HibernateUtils.currentSession();

Criteria cri = session.createCriteria(BookInfo.class);
cr.add(Restrictions.eq("bookid",bnumb);
booklist = cr.list();
bname = boolist.get(0).getName();
//.......................................
obj.put("name", bname);
obj.put("bookid", bnumb);
return obj;
}
}

The errors i get for this are:=

Unresolved compilation errors:-
Illegal modifier for getName() only static final allowed
Duplicate local variable bnumb

So i reverted code back to snippet 1. However, the above mentioned error wont go away. Further, why cant i access db in this class, i have to as i need to get info for the book from DB. If not in this class, then what is the correct method?




Aucun commentaire:

Enregistrer un commentaire