结合反射实现查询封装,返回对应类型对象的集合
现有表t_user:
先建JDBC工具类,JDBCUtils.java
public class JDBCUtils {
private static Properties pro=new Properties();
static{
try {
pro.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("db.properties"));
} catch (IOException e) {
e.printStackTrace();
}
try {
Class.forName(pro.getProperty("driver"));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException {
Connection conn=null;
conn=DriverManager.getConnection(
pro.getProperty("url"),
pro.getProperty("username"),
pro.getProperty("password")
);
return conn;
}