Advertisement
Guest User

Untitled

a guest
Jul 8th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. 1. org.datanucleus.exceptions.NucleusUserException
  2. 2. javax.jdo.JDOUserException
  3.  
  4. @Entity
  5. @PersistenceCapable
  6.  
  7. public class User {
  8.  
  9. @PrimaryKey
  10. @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  11. public String userName;
  12.  
  13. @Persistent
  14. private String name, password, city, bikeModel, age;
  15.  
  16. public User(){
  17.  
  18. }
  19. public User(String name, String uname, String pswd, String age, String city, String bike){
  20. this.name=name;
  21. this.userName=uname;
  22. this.password=pswd;
  23. this.age=age;
  24. this.city=city;
  25. this.bikeModel=bike;
  26. }
  27.  
  28. public String getUserName() {
  29. return userName;
  30. }
  31. //rest of the getters
  32. }
  33.  
  34. //Getting SignUp form values
  35. String name=req.getParameter("name1");
  36. String uname=req.getParameter("uname1");
  37. String pswd=req.getParameter("pswd1");
  38. String age=req.getParameter("age");
  39. String city=req.getParameter("city");
  40. String bike=req.getParameter("bike");
  41.  
  42. //PeristenceManager instance
  43. PersistenceManager pm = PMF.get().getPersistenceManager();
  44.  
  45. //Creating instance for persistent entity class
  46. User newEntry=new User(name,uname,pswd,age,city,bike);
  47.  
  48. //Query to match the userName entered in form and that of the dataStore user
  49. Query q = pm.newQuery(User.class);
  50. q.setFilter("userName == userNameParam");
  51. q.declareParameters("String userNameParam");
  52. try{
  53. List<User> results = (List<User>) q.execute(uname);
  54. if (!results.isEmpty()) {
  55. //if userName is found in DataStore
  56. resp.sendRedirect("invalidUser.html");
  57. } else{
  58. //If userName is not found in dataStore
  59. pm.makePersistent(newEntry);
  60. resp.sendRedirect("success.html");
  61. return;
  62. }
  63. }
  64. finally{
  65.  
  66. System.out.println("Finally!");
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement