Web应用——驾培管理系统之框架搭建

来源:互联网 发布:节奏大师软件下载 编辑:程序博客网 时间:2024/06/12 01:30

前言

       本次项目写一个驾驶员培训管理系统的web后端,前端App端由其他人完成。本次项目暂时没有用到struts2+mybatis+spring3框架,只是用最基础的页面交互获取数据方法实现,算是一个练手项目。

本次项目采用MVC框架,使用工厂设计模式。


本次项目所用包。其中bean为对应的数据库所用数据表对应的实体类,dao为对应的数据库查询接口层,daoimpl为实现层。


org.great.util包下的DBUtils类—获取数据库连接

[java] view plain copy
  1. //Util类,获取数据库连接与释放连接  
  2. public class DBUtils {  
  3.     private static Properties properties = new Properties();  
  4.     private static String url = "";  
  5.     private static String userName = "";  
  6.     private static String pwd = "";  
  7.     static{  
  8.         String config = "db.properties";  
  9.         try {  
  10.             properties.load(DBUtils.class.getClassLoader().getResourceAsStream(config));  
  11.             String Driver = properties.getProperty("driverstr");  
  12.             url = properties.getProperty("url");  
  13.             userName = properties.getProperty("username");  
  14.             pwd = properties.getProperty("password");  
  15.             Class.forName(Driver);        
  16.           
  17.           
  18.         } catch (IOException e) {  
  19.             e.printStackTrace();  
  20.         } catch (ClassNotFoundException e) {  
  21.             e.printStackTrace();  
  22.         }finally{  
  23.               
  24.               
  25.         }  
  26.           
  27.           
  28.     }  
  29.       
  30.     public static Connection getConn(){  
  31.         try {  
  32.             return DriverManager.getConnection(url, userName, pwd);  
  33.         } catch (SQLException e) {  
  34.             // TODO Auto-generated catch block  
  35.             e.printStackTrace();  
  36.         }  
  37.         return null;  
  38.     }  
  39.       
  40.      public static void close(Connection conn,PreparedStatement pre ,ResultSet rs) {  
  41.             if (rs != null) {  
  42.                 try {  
  43.                     rs.close();  
  44.                     rs=null;  
  45.                 } catch (SQLException e) {  
  46.                     e.printStackTrace();  
  47.                 }  
  48.             }  
  49.             if (pre != null) {  
  50.                 try {  
  51.                     pre.close();  
  52.                     pre=null;  
  53.                 } catch (SQLException e) {  
  54.                     e.printStackTrace();  
  55.                 }  
  56.             }  
  57.             if (conn != null) {  
  58.                 try {  
  59.                     conn.close();  
  60.                     conn=null;  
  61.                 } catch (SQLException e) {  
  62.                     e.printStackTrace();  
  63.                 }  
  64.             }  
  65.         }  
  66.         //根据系统当前时间转换格式  
  67.         public static String formatTime(long time) {  
  68.             Date currentTime = new Date();  
  69.             SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
  70.             String dateString = formatter.format(currentTime);  
  71.             return dateString;  
  72.         }  
  73.       
  74. }  


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

[java] view plain copy
  1. driverstr=oracle.jdbc.driver.OracleDriver  
  2. url=jdbc\:oracle\:thin\:@127.0.0.1\:1521\:xe  
  3. username=//oracle数据库用户名  
  4. password=//oracle数据库密码  



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

0 0
原创粉丝点击