反射机制做的框架 跟数据库连接啦

跟数据库的字段相匹配: 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(); } } }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值