- 文件夹构建流程
- dbutils(本文中是BaseDase)工具类放在util文件夹
- dbutils(加载驱动 创建连接 )
public class BaseDao<T> {
private static final String URL = "jdbc:mysql://localhost:3306/accountmanager?characterEncoding = utf-8";
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String USER = "root";
private static final String PASSWORD = "root";
static {
boolean result = DbUtils.loadDriver(DRIVER);
if (result == false) {
try {
throw new SQLException("加载驱动失败");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public Connection getConnection() {
Connection conn = null;
try {
conn = DriverManager.getConnection(URL, USER, PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public <T> T get(String sql, Class<T> clazz, Object[] params) {
T obj = null;
Connection conn