Web应用——驾培管理系统之框架搭建(作者:小圣)

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;
		}
	
}


src目录下的db.properties文件配置:

driverstr=oracle.jdbc.driver.OracleDriver
url=jdbc\:oracle\:thin\:@127.0.0.1\:1521\:xe
username=//oracle数据库用户名
password=//oracle数据库密码




因为笔者的数据库所用的是oracle精简XE版,所以所用的第三方是这个,复制到WEB-INF文件夹的lib文件夹下


至此项目基本框架搭建完毕。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值