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/">

This class contains the employee detail.

ialect jdbc:mysql://localhost:3306/hibernate root true update 操作数据库public class ManageEmployee { private static SessionFactory factory;

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{


本文标签: 变量名 数据库 作者 操作