Web应用——驾培管理系统之框架搭建
前言:本次项目笔者写一个驾驶员培训管理系统的web后端,前端App端由其他人完成。本次项目暂时没有用到struts2+mybatis+spring3框架,只是用最基础的页面交互获取数据方法实现,算是一个练手项目。
本次项目采用MVC框架,使用工厂设计模式。
本次项目所用包。其中bean为对应的数据库所用数据表对应的实体类,dao为对应的数据库查询接口层,daoimpl为实现层。
org.great.util包下的DBUtils类—获取数据库连接
//Util类,获取数据库连接与释放连接
public class DBUtils {
private static Properties properties = new Properties();
private static String url = "";
private static String userName = "";
private static String pwd = "";
static{
String config = "db.properties";
try {
properties.load(DBUtils.class.getClassLoader().getResourceAsStream(config));
String Driver = properties.getProperty("driverstr");
url = properties.getProperty("url");
userName = properties.getProperty("username");
pwd = properties.getProperty("password");
Class.forName(Driver);
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}finally{
}
}
public static Connection getConn(){
try {
return DriverManager.getConnection(url, userName, pwd);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static void close(Connection conn,PreparedStatement pre ,ResultSet rs) {
if (rs != null) {
try {
rs.close();
rs=null;
} catch (SQLException e) {
e.printStackTrace();
}
}
if (pre != null) {
try {
pre.close();
pre=null;
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
conn=null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
//根据系统当前时间转换格式
public static String formatTime(long time) {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
return dateString;
}
}
driverstr=oracle.jdbc.driver.OracleDriver
url=jdbc\:oracle\:thin\:@127.0.0.1\:1521\:xe
username=//oracle数据库用户名
password=//oracle数据库密码
因为笔者的数据库所用的是oracle精简XE版,所以所用的第三方是这个,复制到WEB-INF文件夹的lib文件夹下
至此项目基本框架搭建完毕。