今天又是一上午的建民的课,进行地铁信息系统第一阶段

代码部分

package com.hdq.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
 * 数据库连接工具
 * @author Hu
 *
 */
public class DBUtil {
 
 public static String db_url = "jdbc:mysql://localhost:3306/studentlist";
 public static String db_user = "root";
 public static String db_pass = "password";
 
 public static Connection getConn () {
  Connection conn = null;
  
  try {
   Class.forName("com.mysql.jdbc.Driver");//加载驱动
   conn = DriverManager.getConnection(db_url, db_user, db_pass);
  } catch (Exception e) {
   e.printStackTrace();
  }
  
  return conn;
 }
 
 /**
  * 关闭连接
  * @param state
  * @param conn
  */
 public static void close (Statement state, Connection conn) {
  if (state != null) {
   try {
    state.close();
   } catch (SQLException e) {
    e.printStackTrace();
   }
  }
  
  if (conn != null) {
   try {
    conn.close();
   } catch (SQLException e) {
    e.printStackTrace();
   }
  }
 }
 
 public static void close (ResultSet rs, Statement state, Connection conn) {
  if (rs != null) {
   try {
    rs.close();
   } catch (SQLException e) {
    e.printStackTrace();
   }
  }
  
  if (state != null) {
   try {
    state.close();
   } catch (SQLException e) {
    e.printStackTrace();
   }
  }
  
  if (conn != null) {
   try {
    conn.close();
   } catch (SQLException e) {
    e.printStackTrace();
   }
  }
 }
 public static void main(String[] args) throws SQLException {
//  Connection conn = getConn();
//  PreparedStatement pstmt = null;
//  ResultSet rs = null;
//  String sql ="select * from course";
//  pstmt = conn.prepareStatement(sql);
//  rs = pstmt.executeQuery();
//  if(rs.next()){
//   System.out.println("空");
//  }else{
//   System.out.println("不空");
//  }
 }
}
package com.hdq.service;
import java.util.List;
import com.hdq.dao.ClassDao;
/**
 * CourseService
 * 服务层
 * @author HDQ
 *
 */
public class ClassService {
 ClassDao cDao = new ClassDao();
 
 /**
  * 添加
  * @param course
  * @return
  */
 public boolean add(String table,String strList[],String strList1[]) {
  boolean f = cDao.add(table,strList,strList1);
  return f;
 }
 
 /**
  * 删除
  */
 public boolean del(String table,String qian,String hou) {
  return cDao.delete(table,qian,hou);
 }
 
 /**
  * 修改
  * @return 
  */
 public boolean update(String table,String []strlist,String []strlist1,String qian,String hou) {
  return cDao.update(table,strlist,strlist1,qian,hou);
 }
 /**
  * 查找
  * @return 
  * @throws IllegalAccessException 
  * @throws InstantiationException 
  */
 public <T> List<T> search(String table, String []strList, String []strList1,Class<T> clazz) throws InstantiationException, IllegalAccessException {
  return cDao.search(table,strList,strList1,clazz);
 }
 
 /**
  * 由时间查找
  * @return 
  * @throws IllegalAccessException 
  * @throws InstantiationException 
  */
 public <T> List<T> searchByTime(String table, String []strList, String []strList1,String biaoshi,String qian,String hou,Class<T> clazz) throws InstantiationException, IllegalAccessException {
  return cDao.searchByTime(table, strList, strList1, biaoshi, qian, hou, clazz);
 }
 /**
  * 全部数据
  * @return 
  * @throws IllegalAccessException 
  * @throws InstantiationException 
  * @throws ClassNotFoundException 
  */
 public <T> List<T> list(String table,String []strList,Class<T> clazz) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
  return cDao.list(table,strList,clazz);
 }
 
 /**
  * 创建数据库表单
  * @return 
  * @throws IllegalAccessException 
  * @throws InstantiationException 
  */
 public boolean createTable(String table,String []info,String []type,int []size)
 {
  return cDao.createTable(table, info, type, size);
 }