Beispiel #1
0
 public static ArrayList<Hmajor> selectAll() {
   List<Hmajor> pList = null;
   EntityManager em = DBUtil.getEmFactory().createEntityManager();
   String qString = "select e from Hmajor e";
   TypedQuery<Hmajor> q = (TypedQuery<Hmajor>) em.createQuery(qString, Hmajor.class);
   try {
     pList = q.getResultList();
   } catch (Exception e) {
     System.out.println(e);
   } finally {
     em.close();
   }
   return new ArrayList<Hmajor>(pList);
 }
Beispiel #2
0
 public static ArrayList<Hmajor> majorByDept(String departName) {
   List<Hmajor> cList = null;
   EntityManager em = DBUtil.getEmFactory().createEntityManager();
   String qString = "select e from Hmajor e where e.hdepartment.departname='" + departName + "'";
   TypedQuery<Hmajor> q = (TypedQuery<Hmajor>) em.createQuery(qString, Hmajor.class);
   try {
     cList = q.getResultList();
   } catch (Exception e) {
     System.out.println(e);
   } finally {
     em.close();
   }
   return new ArrayList<Hmajor>(cList);
 }
Beispiel #3
0
 public static void delete(Hmajor aMajor) {
   EntityManager em = DBUtil.getEmFactory().createEntityManager();
   EntityTransaction trans = em.getTransaction();
   trans.begin();
   try {
     em.remove(em.merge(aMajor));
     trans.commit();
   } catch (Exception e) {
     System.out.println(e);
     trans.rollback();
   } finally {
     em.close();
   }
 }
Beispiel #4
0
 public static void update(Bullhorn bullhorn) {
   EntityManager em = DBUtil.getEmFactory().createEntityManager();
   EntityTransaction trans = em.getTransaction();
   trans.begin();
   try {
     em.merge(bullhorn);
     trans.commit();
   } catch (Exception e) {
     System.out.println(e);
     trans.rollback();
   } finally {
     em.close();
   }
 }
Beispiel #5
0
  public static List<Bullhorn> searchPosts(String search) {
    EntityManager em = DBUtil.getEmFactory().createEntityManager();
    List<Bullhorn> searchposts = null;
    String qString = "select b from Bullhorn b where b.post like :search";

    try {
      Query query = em.createQuery(qString);
      query.setParameter("search", "%" + search + "%");
      searchposts = query.getResultList();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      em.close();
    }
    return searchposts;
  }
Beispiel #6
0
  public static List<Bullhorn> postsofUser(long userid) {
    EntityManager em = DBUtil.getEmFactory().createEntityManager();
    List<Bullhorn> userposts = null;
    String qString = "select b from Bullhorn b where b.userid = :userid";

    try {
      Query query = em.createQuery(qString);
      query.setParameter("userid", userid);
      userposts = query.getResultList();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      em.close();
    }
    return userposts;
  }
Beispiel #7
0
  public static List<Bullhorn> postBullhorn() {
    EntityManager em = DBUtil.getEmFactory().createEntityManager();
    String qString = "select b from Bullhorn b";

    List<Bullhorn> posts = null;
    try {
      Query query = em.createQuery(qString);
      posts = query.getResultList();

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      em.close();
    }
    return posts;
  }
Beispiel #8
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    EntityManager em = DBUtil.getEmFactory().createEntityManager();
    String name = request.getParameter("name");
    String username = request.getParameter("username");
    String userpass = request.getParameter("userpass");

    try {
      Tuser u = new Tuser();
      u.setTname(name);
      u.setUsername(username);
      u.setUserpass(userpass);
      DBUtil.insert(u);
      getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
    } catch (Exception e) {
      System.out.println(e);
    } finally {
      em.close();
    }
  }