Advertisement
Guest User

Untitled

a guest
Feb 25th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. private static SessionFactory sf;
  2.  
  3.  
  4.  
  5. public void setup() {
  6.  
  7.  
  8. try {
  9.  
  10.  
  11.  
  12. sf = new AnnotationConfiguration().configure()
  13.  
  14.  
  15. .addPackage("com.registration.domain")
  16.  
  17.  
  18. .addAnnotatedClass
  19.  
  20. } catch (Throwable e) {
  21.  
  22.  
  23. System.out.println(e);
  24.  
  25.  
  26. }
  27.  
  28.  
  29.  
  30. }
  31.  
  32.  
  33.  
  34. void verifyUser(String usernm,String passwd)
  35.  
  36.  
  37. {
  38.  
  39.  
  40. Session session = sf.openSession();
  41.  
  42.  
  43. Transaction tx = null;
  44.  
  45.  
  46. try{
  47.  
  48.  
  49. tx = session.beginTransaction();
  50.  
  51.  
  52. List<?> lst = session.createQuery("FROM LoginPojo").list();
  53.  
  54.  
  55. for (Iterator<?> iterator =
  56.  
  57.  
  58. lst.iterator(); iterator.hasNext();){
  59.  
  60.  
  61. LoginPojo lpojo = (LoginPojo) iterator.next();
  62.  
  63.  
  64. System.out.print("Username: " + lpojo.getUsernm());
  65.  
  66.  
  67. System.out.print(" Password: " + lpojo.getPasswd());
  68.  
  69.  
  70.  
  71. if(lpojo.getUsernm().equals(usernm)&& lpojo.getPasswd
  72.  
  73. System.out.println("Correct username and password");
  74.  
  75.  
  76. }
  77.  
  78.  
  79. else
  80.  
  81.  
  82. {
  83.  
  84.  
  85. System.out.println("Incorrect username and password");
  86.  
  87.  
  88. }
  89.  
  90.  
  91.  
  92.  
  93.  
  94. }
  95. tx.commit();
  96.  
  97.  
  98. }catch (HibernateException e) {
  99.  
  100.  
  101. if (tx!=null) tx.rollback();
  102.  
  103.  
  104. e.printStackTrace();
  105.  
  106.  
  107. }finally {
  108.  
  109.  
  110. session.close();
  111.  
  112.  
  113. }
  114.  
  115.  
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement