admin 管理员组文章数量: 1184232
2024年1月10日发(作者:python变量名必须以)
create table EMPLOYEE ( id INT NOT NULL auto_increment, first_name VARCHAR(20) default NULL, last_name VARCHAR(20) default NULL, salary INT default NULL, PRIMARY KEY (id));
"-//Hibernate/Hibernate Mapping DTD//EN" "/dtd/">
public static void main(String[] args) { try{ factory = new Configuration().configure().buildSessionFactory(); }catch (Throwable ex) {
n("Failed to create sessionFactory object." + ex); throw new ExceptionInInitializerError(ex);
} ManageEmployee ME = new ManageEmployee(); /* Add few employee records in database */ Integer empID1 = loyee("Zara", "Ali", 1000); Integer empID2 = loyee("Daisy", "Das", 5000); Integer empID3 = loyee("John", "Paul", 10000); /* List down all the employees */ ployees(); /* Update employee's records */
/* Update employee's records */ Employee(empID1, 5000); /* Delete an employee from the database */ Employee(empID2); /* List down new list of the employees */ ployees(); } /* Method to CREATE an employee in the database */ public Integer addEmployee(String fname, String lname, int salary){ Session session = ssion(); Transaction tx = null; Integer employeeID = null; try{ tx = ransaction(); Employee employee = new Employee(fname, lname, salary); employeeID = (Integer) (employee);
(); }catch (HibernateException e) { if (tx!=null) ck(); tackTrace();
}finally { ();
} return employeeID; } /* Method to READ all the employees */ public void listEmployees( ){ Session session = ssion(); Transaction tx = null; try{ tx = ransaction(); List employees = Query("FROM Employee").list();
for (Iterator iterator =
or(); t();){ Employee employee = (Employee) ();
("First Name: " + stName());
(" Last Name: " + tName());
n(" Salary: " + ary());
} (); }catch (HibernateException e) { if (tx!=null) ck(); tackTrace();
}finally { ();
} } /* Method to UPDATE salary for an employee */ public void updateEmployee(Integer EmployeeID, int salary ){ Session session = ssion(); Transaction tx = null; try{ tx = ransaction(); Employee employee =
(Employee)(, EmployeeID);
ary( salary ); (employee);
(); }catch (HibernateException e) { if (tx!=null) ck(); tackTrace();
}finally { ();
} } /* Method to DELETE an employee from the records */ public void deleteEmployee(Integer EmployeeID){ Session session = ssion(); Transaction tx = null; try{ tx = ransaction();
//addPackage("") //add package if used. addAnnotatedClass(). buildSessionFactory(); }catch (Throwable ex) {
n("Failed to create sessionFactory object." + ex); throw new ExceptionInInitializerError(ex);
} ManageEmployee ME = new ManageEmployee(); /* Add few employee records in database */ Integer empID1 = loyee("Zara", "Ali", 1000); Integer empID2 = loyee("Daisy", "Das", 5000); Integer empID3 = loyee("John", "Paul", 10000); /* List down all the employees */ ployees(); /* Update employee's records */ Employee(empID1, 5000); /* Delete an employee from the database */ Employee(empID2); /* List down new list of the employees */ ployees(); } /* Method to CREATE an employee in the database */ public Integer addEmployee(String fname, String lname, int salary){ Session session = ssion(); Transaction tx = null; Integer employeeID = null; try{ tx = ransaction(); Employee employee = new Employee(); stName(fname); tName(lname); ary(salary); employeeID = (Integer) (employee);
(); }catch (HibernateException e) { if (tx!=null) ck(); tackTrace();
}finally { ();
} return employeeID; } /* Method to READ all the employees */ public void listEmployees( ){ Session session = ssion(); Transaction tx = null; try{ tx = ransaction(); List employees = Query("FROM Employee").list();
for (Iterator iterator =
or(); t();){ Employee employee = (Employee) ();
("First Name: " + stName());
(" Last Name: " + tName());
n(" Salary: " + ary());
} (); }catch (HibernateException e) { if (tx!=null) ck(); tackTrace();
}finally { ();
} } /* Method to UPDATE salary for an employee */ public void updateEmployee(Integer EmployeeID, int salary ){ Session session = ssion(); Transaction tx = null; try{
版权声明:本文标题:Hibernate框架简介 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1704893919a465951.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论