代码:火车票预订系统的设计与实现

上传人:s9****2 文档编号:509068255 上传时间:2023-06-10 格式:DOCX 页数:43 大小:65.31KB
返回 下载 相关 举报
代码:火车票预订系统的设计与实现_第1页
第1页 / 共43页
代码:火车票预订系统的设计与实现_第2页
第2页 / 共43页
代码:火车票预订系统的设计与实现_第3页
第3页 / 共43页
代码:火车票预订系统的设计与实现_第4页
第4页 / 共43页
代码:火车票预订系统的设计与实现_第5页
第5页 / 共43页
点击查看更多>>
资源描述

《代码:火车票预订系统的设计与实现》由会员分享,可在线阅读,更多相关《代码:火车票预订系统的设计与实现(43页珍藏版)》请在金锄头文库上搜索。

1、个人收集整理 勿做商业用途目录第一部分 功能代码 - 1 -1。DBO。 JAVA - 12.LOG.JAVA - 4-3。MD5.JAVA - 5-4。COMMON.JAVA - 6-5。CHECKCODE.JAVA - 8-6。LOGINSERVLETJAVA -8-7. TRAINBEAN.JAVA-13-第二部分 外部显示代码 - 22 -1。INDEX。 JSP-222.LOGIN。 JSP-263.ERROR.JSP-304.INDEX。 JSP-315.INDEX.JSP-33-第一部分 内部功能代码1. DBO 。 javapackage com.util ;import ja

2、va。sql。*;import java.sql.DriverManager;import java 。 sql.ResultSet;import java 。 sql。 SQLException ;import javax.activation 。 DataSource;import java.sql. ;import java 。 sql。 DriverManager;import java 。 sql.ResultSet;import java 。 sql.SQLException;import java.sql.Statement;import javax 。 naming。 Cont

3、ext;import javax.naming.InitialContext ;public class DBO private Connection conn ;private Statement stmt ;private DataSource ds ;public DBO () /*打开数据库*/public void open( )try Class。forName (” orgg gjt。mm.mysql.Driver );conn = DriverManager.getConnection(jdbc:mysql:/localhost : 3306/cpyd?user=root&pa

4、ssword=siminguseUnicode=true&characterEncoding=GBK ”) ;stmt=conn.createStatement( );System。out.println (”打开数据库连接);catch (Exception ex) System.err.println (”打开数据库时出错 : + ex.getMessage () );/*关闭数据库,将连接返还给连接池/public void close( ) try / connMgr 。 freeConnection ( java , conn ) ; conn 。 close();System 。

5、out。 println (”释放连接”);catch ( SQLException ex )System。 err.println (” 返还连接池出错:+ ex。 getMessage();/*执行查询*/public ResultSet executeQuery(String sql ) throws SQLException ResultSet rs = null ;rs = stmt 。 executeQuery(sql);System 。 out.println (”执行查询 );return rs;/执行增删改*/public int executeUpdate( String

6、sql) throws SQLException int ret = 0;ret = stmt 。 executeUpdate(sql );System。out。printin (” 执行增删改”); return ret;/*将 SQL 语句加入到批处理*/pubiic void addBatch ( String sqi ) throws SQLException stmt。 addBatch (sqi);/执行批处理*/public int executeBatch () throws SQLException booiean isAuto=conn 。 getAutoCommit();

7、 conn.setAutoCommit ( false); int updateCounts = stmt 。 executeBatch(); /conn 。 commit(); /conn 。 setAutoCommit(isAuto) ; /conn 。 setAutoCommit(true); return updateCounts ;public boolean getAutoCommit ( ) throws SQLException return conn.getAutoCommit() ;public void setAutoCommit ( boolean auto ) thr

8、ows SQLException conn.setAutoCommit (auto);public void commit( ) throws SQLException conn 。 commit( ) ;/ this。 close();public void rollBack() throws SQLException conn 。 rollback ();/ this.close( );2. Log.javapackage com.util;/* 日志/import java。io。BufferedWriter ;import java.io.File ;import java.io 。

9、FileNotFoundException; import java.io 。 FileWriter ;import java.io 。 IOException ;import java 。 io。 PrintWriter ;public class Log public void addLog(String str)try File file=new File(c:/log.txt );”FileWriter fw=new FileWriter (file,true); BufferedWriter bw=new BufferedWriter(fw) ; PrintWriter pw = n

10、ewPrintWriter(bw );pw.write(str );bw。 newLine (); /断行bw。 flush (); /将数据更新至文件pw。 close( );fw。 close( ); /关闭文件流 catch(FileNotFoundException e )System 。 out。 println ( 警告:日志文件没找到! !!”); e。 printStackTrace ( ); catch (IOException e) System 。 out.println ( 警告:日志文件 IO 错误! !);e。 printStackTrace ();3. MD5 。

11、 javapackage com.util ;/MD5 密码加密类/import java.security. ;import java。security.spec。*;public final class MD5 public final static String MD5 (String s) char hexDigits = ,01,2, 3, ,5, 64, 7, 8, 9 ,,ac,, db,e ftry byte strTemp = s.getBytes ();MessageDigest mdTemp = MessageDigest 。 getInstance (”MD5”) md

12、Temp.update(strTemp );byte md = mdTemp 。 digest( );int j = md 。 length ;char str = new charj 2;int k = 0 ;for (int i = 0; i j;i+) byte byte0 = mdi ;strk+ = hexDigitsbyte0 4 & 0xf;strk+ = hexDigits byte0 & 0xf ;return new String(str );catch ( Exception e )return null;4. Common.javapackage com.util ;/

13、* 常用方法类/import java。text。SimpleDateFormat;import java 。 util.Calendar;import java.util 。 Date;public final class Com mon/ 字符串 HTML 转换public static String turn (String str) while (str.indexOf (n) != 1)str = str 。 substring(0, str 。 indexOf( ”n) + + str。 substring (str.indexOf(n) + 1);while (str.index

14、Of (” ) !=-1)str = str.substring (0, str.indexOf ( ”) +nbsp ;”+ str.substring(str.indexOf ( ) + 1 );return str ;/ 返回日期 当前日期传入 0 一年之前传入 -1 三年后传入 3 public static String getDate (int num) SimpleDateFormat df = new SimpleDateFormat(yyyy-MMdd);Calendar c = Calendar 。 getInstance();c。 add(Calendar 。 YEAR, num );return df.format(c.getTime ();/ 数据库输出字符串的过滤public static String SQLStr(String str)if (str ! = null &

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号