package shjt.core.dbUtil; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.Properties; import shjt.core.model.KsSqrjxjyxx; public class DBUtil { public static Connection conn = null; public static PreparedStatement ps = null; public static ResultSet rs = null; public static Connection openConn() { InputStream is = DBUtil.class.getClassLoader().getResourceAsStream("config.properties"); try { try { Properties prop = new Properties(); prop.load(is); String driverClass = prop.getProperty("mysql_driverClass"); try { Class.forName(driverClass); String url = prop.getProperty("mysql_url"); String username = prop.getProperty("mysql_username"); String password = prop.getProperty("mysql_password"); conn = (Connection) DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } } catch (SQLException e) { e.printStackTrace(); } return conn; } public static void closeConn(Connection conn) { if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } //查询继续教育信息(数据来自于报名软件Mysql数据库ks_sqrjxjyxx表中的数据) public static List<KsSqrjxjyxx> findContinEducation(String sfzh) throws ParseException{ conn = openConn(); List<KsSqrjxjyxx> list = new ArrayList<KsSqrjxjyxx>(); KsSqrjxjyxx ksSqrjxjyxx = null; SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd"); try { String sql = "select * from ks_sqrjxjyxx k where k.sfzh = ?"; ps = conn.prepareStatement(sql); ps.setString(1, sfzh); rs = ps.executeQuery(); while(rs.next()){ ksSqrjxjyxx = new KsSqrjxjyxx(); ksSqrjxjyxx.setBz(rs.getString("bz")); ksSqrjxjyxx.setCszt(rs.getString("cszt")); ksSqrjxjyxx.setDbzt(rs.getString("dbzt")); ksSqrjxjyxx.setDbztAgain(rs.getString("dbztAgain")); ksSqrjxjyxx.setDbztls(rs.getString("dbztls")); ksSqrjxjyxx.setGw(rs.getString("gw")); ksSqrjxjyxx.setHy(rs.getString("hy")); ksSqrjxjyxx.setHylbbh(rs.getString("hylbbh")); ksSqrjxjyxx.setJxjylbbh(rs.getString("jxjylbbh")); ksSqrjxjyxx.setKscj(rs.getString("kscj")); ksSqrjxjyxx.setKsdate(f.parse(f.format(rs.getDate("ksdate")))); ksSqrjxjyxx.setLogid(rs.getString("logid")); ksSqrjxjyxx.setPxbbh(rs.getString("pxbbh")); ksSqrjxjyxx.setPxjgbh(rs.getString("pxjgbh")); ksSqrjxjyxx.setPxjsdate(f.parse(f.format(rs.getDate("pxjsdate")))); ksSqrjxjyxx.setPxksdate(f.parse(f.format(rs.getDate("pxksdate")))); ksSqrjxjyxx.setPxxxbh(rs.getString("pxxxbh")); ksSqrjxjyxx.setSbdwmc(rs.getString("sbdwmc")); ksSqrjxjyxx.setSfzh(rs.getString("sfzh")); ksSqrjxjyxx.setSqrdwbh(rs.getString("sqrdwbh")); ksSqrjxjyxx.setSqrdwmc(rs.getString("sqrdwmc")); ksSqrjxjyxx.setXm(rs.getString("xm")); ksSqrjxjyxx.setXybh(rs.getString("xybh")); ksSqrjxjyxx.setXybhbk(rs.getString("xybhbk")); ksSqrjxjyxx.setZcsj(f.parse(f.format(rs.getDate("zcsj")))); ksSqrjxjyxx.setZgzh(rs.getString("zgzh")); list.add(ksSqrjxjyxx); } return list; } catch (SQLException e) { e.printStackTrace(); } return null; } }