您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 代码:火车票预订系统的设计与实现
火车票预定系统的设计与实现I目录第一部分功能代码.........................................................................................................................-1-1.DBO.JAVA.......................................................................................................................................-1-2.LOG.JAVA.........................................................................................................................................-4-3.MD5.JAVA.......................................................................................................................................-5-4.COMMON.JAVA.................................................................................................................................-6-5.CHECKCODE.JAVA..............................................................................................................................-8-6.LOGINSERVLET.JAVA...........................................................................................................................-9-7.TRAINBEAN.JAVA............................................................................................................................-13-第二部分外部显示代码...............................................................................................................-24-1.INDEX.JSP......................................................................................................................................-24-2.LOGIN.JSP......................................................................................................................................-27-3.ERROR.JSP......................................................................................................................................-31-4.INDEX.JSP......................................................................................................................................-32-5.INDEX.JSP......................................................................................................................................-35-火车票预定系统的设计与实现软件职业技术学院062402班斯明学号:20063342-1-第一部分内部功能代码1.DBO.javapackagecom.util;importjava.sql.*;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjavax.activation.DataSource;importjava.sql.*;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjavax.naming.Context;importjavax.naming.InitialContext;publicclassDBO{privateConnectionconn;privateStatementstmt;privateDataSourceds;publicDBO(){}/**打开数据库*/publicvoidopen(){try{Class.forName(org.gjt.mm.mysql.Driver);conn=火车票预定系统的设计与实现软件职业技术学院062402班斯明学号:20063342-2-DriverManager.getConnection(jdbc:mysql://localhost:3306/cpyd?user=root&password=siming&useUnicode=true&characterEncoding=GBK);stmt=conn.createStatement();System.out.println(打开数据库连接);}catch(Exceptionex){System.err.println(打开数据库时出错:+ex.getMessage());}}/**关闭数据库,将连接返还给连接池*/publicvoidclose(){try{//connMgr.freeConnection(java,conn);conn.close();System.out.println(释放连接);}catch(SQLExceptionex){System.err.println(返还连接池出错:+ex.getMessage());}}/**执行查询*/publicResultSetexecuteQuery(Stringsql)throwsSQLException{ResultSetrs=null;rs=stmt.executeQuery(sql);System.out.println(执行查询);returnrs;}/**火车票预定系统的设计与实现软件职业技术学院062402班斯明学号:20063342-3-执行增删改*/publicintexecuteUpdate(Stringsql)throwsSQLException{intret=0;ret=stmt.executeUpdate(sql);System.out.println(执行增删改);returnret;}/**将SQL语句加入到批处理*/publicvoidaddBatch(Stringsql)throwsSQLException{stmt.addBatch(sql);}/**执行批处理*/publicint[]executeBatch()throwsSQLException{booleanisAuto=conn.getAutoCommit();conn.setAutoCommit(false);int[]updateCounts=stmt.executeBatch();//conn.commit();//conn.setAutoCommit(isAuto);//conn.setAutoCommit(true);returnupdateCounts;}publicbooleangetAutoCommit()throwsSQLException{returnconn.getAutoCommit();}publicvoidsetAutoCommit(booleanauto)throwsSQLException{conn.setAutoCommit(auto);}火车票预定系统的设计与实现软件职业技术学院062402班斯明学号:20063342-4-publicvoidcommit()throwsSQLException{conn.commit();//this.close();}publicvoidrollBack()throwsSQLException{conn.rollback();//this.close();}}2.Log.javapackagecom.util;/***日志*/importjava.io.BufferedWriter;importjava.io.File;importjava.io.FileNotFoundException;importjava.io.FileWriter;importjava.io.IOException;importjava.io.PrintWriter;publicclassLog{publicvoidaddLog(Stringstr){try{Filefile=newFile(c://log.txt);FileWriterfw=newFileWriter(file,true);BufferedWriterbw=newBufferedWriter(fw);PrintWriterpw=newPrintWriter(bw);pw.write(str);bw.newLine();//断行bw.flush();//将数据更新至文件火车票预定系统的设计与实现软件职业技术学院062402班斯明学号:20063342-5-pw.close();fw.close();//关闭文件流}catch(FileNotFoundExceptione){System.out.println(警告:日志文件没找到!!!!);e.printStackTrace();}catch(IOExceptione){System.out.println(警告:日志文件IO错误!!!!);e.printStackTrace();}}}3.MD5.javapackagecom.util;/***MD5密码加密类**/importjava.security.*;importjava.security.spec.*;publicfinalclassMD5{publicfinalstaticStringMD5(Strings){charhexDigits[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};try{byte[]strTemp=s
本文标题:代码:火车票预订系统的设计与实现
链接地址:https://www.777doc.com/doc-4248319 .html