資源簡介
java機票管理系統

代碼片段和文件信息
package?com.f313.dao;
import?com.f313.entity.Flight;
import?com.f313.entity.FlightDetails;
import?com.f313.entity.PassagerBean;
import?com.f313.util.JdbcUtils;
import?com.f313.util.Xx2xx;
import?java.sql.Connection;
import?java.sql.PreparedStatement;
import?java.sql.ResultSet;
import?java.sql.SQLException;
import?java.sql.Statement;
import?java.util.ArrayList;
import?java.util.List;
import?java.util.logging.Level;
import?java.util.logging.Logger;
public?class?FlightDAO?{
private?static?final?boolean?D?=?true;
private?static?final?Logger?log?=?Logger.getLogger(“FlightDAO“);
public?void?add(Flight?flight)?throws?Exception{
Connection?conn?=?JdbcUtils.getConnection();
PreparedStatement?ps?=?null;
try{
conn?=?JdbcUtils.getConnection();
String?sql?=?“insert?into?flight?values?(???????)“;
ps?=?conn.prepareStatement(sql);
ps.setString(1?flight.getFid());
ps.setString(2?flight.getFstart());
ps.setString(3?flight.getFend());
ps.setString(4?String.valueOf(flight.getFnumber()));
ps.setTimestamp(5?new?java.sql.Timestamp(flight.getFtime().getTime()));
ps.setInt(6?flight.getFsum());
ps.setDouble(7?flight.getPrice());
int?row?=?ps.executeUpdate();
if?(row?>?0)?{
if(D)
log.log(Level.WARNINGflight.getFid()+“添加成功“);
return?;
}else{
if(D)
log.log(Level.WARNINGflight.getFid()+“添加失敗“);
//?TODO?應該自定義異常
throw?new?Exception(“添加失敗“);
}
}catch(SQLException?e){
if(D)log.log(Level.WARNING“--?FlightDAO?add()?--“);
e.printStackTrace();
throw?e;
}finally{
ps.close();
conn.close();
}
}
public?void?delete(Flight?flight)?throws?SQLException{
Connection?conn?=?JdbcUtils.getConnection();
Statement?st?=?null;
ResultSet?rs?=?null;
try{
st?=?conn.createStatement();
String?sql?=?“delete?from?flight?where?fid=‘“+flight.getFid()+“‘“;
st.executeUpdate(sql);
}catch(SQLException?e){
if(D)log.log(Level.WARNING“--?FlightDAO?delete()?--“);
e.printStackTrace();
throw?e;
}finally{
JdbcUtils.free(rs?st?conn);
}
}
public?List?find()?throws?SQLException{
Connection?conn?=?JdbcUtils.getConnection();
List?list?=?new?ArrayList();
Statement?st?=?null;
ResultSet?rs?=?null;
try{
st?=?conn.createStatement();
String?sql?=?“select?*?from?flight“;
rs?=?st.executeQuery(sql);
while(rs.next()){
Flight?flight?=?new?Flight();
flight.setFid(rs.getString(“fid“));
flight.setFstart(rs.getString(“fstart“));
????flight.setFend(rs.getString(“fend“));
????flight.setFnumber(rs.getInt(“fnumber“));
????flight.setFtime(rs.getobject(“ftime“));
????flight.setFsum(rs.getInt(“fsum“));
????flight.setPrice(rs.getDouble(“price“));
list.add(flight);?
}
}catch(SQLException?e){
if(D)log.log(Level.WARNING“--?FlightDAO?find()?--“);
e.printStackTrace();
throw?e;
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-04-28?12:18??tk\
?????文件?????????839??2015-04-28?12:34??tk\.classpath
?????目錄???????????0??2015-04-28?12:09??tk\.myeclipse\
?????文件?????????279??2015-04-28?12:22??tk\.myme
?????文件????????1745??2015-04-28?12:09??tk\.project
?????目錄???????????0??2015-04-28?12:09??tk\.settings\
?????文件?????????500??2015-04-28?12:09??tk\.settings\.jsdtscope
?????文件?????????364??2015-04-28?12:09??tk\.settings\org.eclipse.jdt.core.prefs
?????文件?????????444??2015-04-28?12:09??tk\.settings\org.eclipse.wst.common.component
?????文件?????????252??2015-04-28?12:09??tk\.settings\org.eclipse.wst.common.project.facet.core.xm
?????文件??????????49??2015-04-28?12:09??tk\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件???????????6??2015-04-28?12:09??tk\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????目錄???????????0??2015-04-28?12:18??tk\src\
?????目錄???????????0??2015-04-28?12:23??tk\src\com\
?????目錄???????????0??2015-04-28?12:21??tk\src\com\f313\
?????目錄???????????0??2015-04-28?12:21??tk\src\com\f313\dao\
?????文件????????6182??2015-04-28?12:21??tk\src\com\f313\dao\FlightDAO.java
?????文件????????1297??2015-04-28?12:56??tk\src\com\f313\dao\PassagerDAO.java
?????文件????????1145??2015-04-28?12:21??tk\src\com\f313\dao\TicketDAO.java
?????目錄???????????0??2015-04-28?12:21??tk\src\com\f313\entity\
?????文件????????1304??2015-04-28?13:14??tk\src\com\f313\entity\Flight.java
?????文件?????????724??2015-04-28?12:21??tk\src\com\f313\entity\FlightDetails.java
?????文件?????????884??2015-04-28?13:15??tk\src\com\f313\entity\PassagerBean.java
?????文件?????????723??2015-04-28?13:16??tk\src\com\f313\entity\Ticket.java
?????目錄???????????0??2015-04-28?12:20??tk\src\com\f313\filter\
?????文件????????1027??2015-06-28?10:47??tk\src\com\f313\filter\DefaultEncodingFilter.java
?????文件????????1087??2015-04-28?13:16??tk\src\com\f313\filter\LoginFilter.java
?????目錄???????????0??2015-04-28?12:21??tk\src\com\f313\service\
?????文件?????????627??2015-04-28?12:20??tk\src\com\f313\service\FlightService.java
?????目錄???????????0??2015-04-28?12:21??tk\src\com\f313\service\impl\
?????文件????????2034??2015-04-28?12:21??tk\src\com\f313\service\impl\FlightServiceImpl.java
............此處省略84個文件信息
評論
共有 條評論