附 录
以下是此次项目开发中的一部分核心代码,贴出供大家参考: 1) 处理的多个查询条件的主要要代码如下:
public Criteria findAdminList(String name,String loginname,
String enrolldate,String enrolldate2) throws ParseException{
DateFormat df = DateFormat.getDateInstance(); Date datefrom = (Date) df.parse(enrolldate); Date dateto = (Date) df.parse(enrolldate2);
SessionFactory sessionFactory = ht.getSessionFactory(); session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(Admins.class); if(name!=null){ criteria.add(Restrictions.eq(\, name));
}
if(loginname!=null){ criteria.add(Restrictions.eq(\, loginname)); }
if(enrolldate!=null){ criteria.add(Restrictions.ge(\,datefrom)); }
if(enrolldate!=null){ criteria.add(Restrictions.le(\, dateto)); }
return criteria;
}
2) 处理分页的主要代码如下:
public List
String enrolldate, String enrolldate2,int pageNum, int pageRows) List
try{
26
{
}
Criteria criteria = findAdminList(name, loginname, enrolldate, enrolldate2); list = criteria.setFirstResult((pageNum-1)*pageRows). setMaxResults(pageRows).list(); if(session!=null) session.close(); return list;
}catch (Exception e) { }
e.printStackTrace(); return list;
3)以下是从外部文件读取JDBC连接数据库的代码: public class JDBCUtils {
private static Properties config = new Properties(); static { }
public static Connection getConnection() {
try{
String driver = config.getProperty(\); String dburl = config.getProperty(\);
27
InputStream in = null; try {
ClassLoader loader = JDBCUtils.class.getClassLoader(); in = loader.getResourceAsStream(\); config.load(in);
} catch(IOException e){
throw new ExceptionInInitializerError();
} finally { }
try{ in.close(); }catch(Exception e){}
}
String username = config.getProperty(\); String password = config.getProperty(\);
Class.forName(driver);
Connection con = DriverManager.getConnection(dburl, username, password); return con;
} catch(ClassNotFoundException e){
System.out.println(\); throw new RuntimeException(e);
}catch (SQLException e) { }
System.out.println(\); throw new RuntimeException(e);
public static void close(ResultSet rs, Statement st, Connection con) { }
close(rs); close(st, con);
public static void close(Statement st, Connection con) { }
close(st); close(con);
public static void close(ResultSet rs) {
try {
rs.close();
} catch (Exception e) { }
28
}
public static void close(Statement st) { }
public static void close(Connection con) { }
try {
con.close(); try {
st.close();
} catch (Exception e) { }
} catch (Exception e) { }
29
致 谢
感谢此次毕业设计中给于我技术支持的导师胡子义教授,他严谨细致、一丝不苟的作风一直是我工作、学习中的榜样;他循循善诱的教导和不拘一格的思路给予我无尽的启迪。
另外还要感谢我的项目经理:庞琪,一起开发项目的同学,(和我一起完成电信计费系统的还有何战魁、杨愿强。在合作期间,大家团结合作,系统模块上分工合作,异常问题上通力配合,共同为降低系统的耦合,形成统一的接口,降低代码冗余,提高系统效率而努力。)还有那些在QQ问问、CSDN论坛里给于我技术帮助的各位热心的佚名者。
30