跟数据库的字段相匹配: package com.simple.entity; public class UserInfo { private int id; private String name; private String password; public UserInfo() { } public UserInfo(String name, String password) { super(); this.name = name; this.password = password; } public UserInfo(int id, String name, String password) { super(); this.id = id; this.name = name; this.password = password; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } ----------------------------------------------------------------------------------------------------- package com.simple.entity; import java.io.Serializable; import java.util.Date; public class ProductInfo{ private int id; private String name; private double price; private Date date; public ProductInfo() { super(); } public ProductInfo(String name, double price, Date date) { super(); this.name = name; this.price = price; this.date = date; } public ProductInfo(int id, String name, double price, Date date) { super(); this.id = id; this.name = name; this.price = price; this.date = date; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } } ------------------------------------------------------------------------------------ package com.simple.entity; import java.util.Date; public class EmployeeInfo { private int id; private String employeeName; private double salary; private Date birthday; private String department; public EmployeeInfo() { super(); } public EmployeeInfo(String employeeName, double salary, Date birthday, String department) { super(); this.employeeName = employeeName; this.salary = salary; this.birthday = birthday; this.department = department; } public EmployeeInfo(int id, String employeeName, double salary, Date birthday, String department) { super(); this.id = id; this.employeeName = employeeName; this.salary = salary; this.birthday = birthday; this.department = department; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getEmployeeName() { return employeeName; } public void setEmployeeName(String employeeName) { this.employeeName = employeeName; } public double getSalary() { return salary; } public void setSalary(double salary) { this.salary = salary; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public String getDepartment() { return department; } public void setDepartment(String department) { this.department = department; } } ------------------------------------------------------------------------------------------------------ 连接数据库的代码: package com.simple.hibernate; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DBUtil { public static Connection getConnection(){ try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); return DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=test","sa",""); } catch (ClassNotFoundException e) { e.printStackTrace(); return null; } catch (SQLException e) { e.printStackTrace(); return null; } } public static void close(Connection con){ try { if(con!=null&&!con.isClosed()){ con.close(); } } catch (SQLException e) { e.printStackTrace(); } } } --------------------------------------------------------------------------------------------------------------------- 反射机制做的框架 对于数据库做增、删、改、查 package com.simple.hibernate; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DBUtil { public static Connection getConnection(){ try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); return DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=test","sa",""); } catch (ClassNotFoundException e) { e.printStackTrace(); return null; } catch (SQLException e) { e.printStackTrace(); return null; } } public static void close(Connection con){ try { if(con!=null&&!con.isClosed()){ con.close(); } } catch (SQLException e) { e.printStackTrace(); } } }
反射机制做的框架 跟数据库连接啦
最新推荐文章于 2024-11-12 10:56:30 发布