import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
//-------------------------------------------------------------------------------------
class PlaylistVO{
private Timestamp ptime;
private int movieNumber=0;
private String roomid;
public void setPtime(Timestamp ptime){
this.ptime=ptime;
}
public void setMovidNumber(int movieNumber){
this.movieNumber=movieNumber;
}
public void setRoomid(String roomid){
this.roomid=roomid;
}
public Timestamp getTimestamp(){
return ptime;
}
public int getMovieNumber(){
return movieNumber;
}
public String getRoomid(){
return roomid;
}
}
//--------------------------------------------------------------------------------------
class SeatsVO{
private Timestamp ptime;
private int movieNumber=0;
private String seat_num;
private String sold;
private int custID;
public void setTimestamp(Timestamp ptime){
this.ptime=ptime;
}
public void setMovidNumber(int movieNumber){
this.movieNumber=movieNumber;
}
public void setSeat_num(String seat_num){
this.seat_num=seat_num;
}
public void setSold(String sold){
this.sold=sold;
}
public void setCustID(int custID){
this.custID=custID;
}
public Timestamp getDate(){
return ptime;
}
public int getMovidNumber(){
return movieNumber;
}
public String getSeat_num(){
return seat_num;
}
public String getSold(){
return sold;
}
public int getCustID(){
return custID;
}
}
//------------------------------------------------------------------------------------------
class MovieSql {
private static final String SELECT_PLAYLIST ="Select ptime,movie,roomid from playlist";
private static final String INSTER_PLAYLIST ="insert into playlist values (?,?,?)";
private static final String DLELTE_PLAYEIST ="delete playlist where --------";
// private static final String UPDATE_PLAYEIST ="update playlist set (?,?,?) where ";
private static final String SELECT_SEATS ="Select ptime,movie,roomid from playlist";
private static final String INSTER_SEATS ="insert into seats values (?,?,?,?,?)";
private static final String DLELTE_SEATS ="delete seats where --------";
// private static final String UPDATE_PLAYEIST ="update playlist set (?,?,?) where";
private static final String SELECT_M_ROOM="select roomid,seat_row,seat_col from m_room where roomid=?";
Connection conn=null;
public void setConnection() throws SQLException{
String conUrl = "jdbc:sqlserver://localhost:1433;databaseName=movie";
conn=DriverManager.getConnection(conUrl, "sa", "passw0rd");
}
public void insertPalylist(PlaylistVO play) throws SQLException{
int seat_r=0;
int seat_c=0;
CallableStatement cs=conn.prepareCall(INSTER_PLAYLIST);
cs.setString(1,play.getTimestamp().toString());
cs.setInt(2,play.getMovieNumber());
cs.setString(3,play.getRoomid());
int success=cs.executeUpdate();
System.out.println("Playlist成功更新"+success+"筆");
String room=play.getRoomid();
cs=conn.prepareCall(SELECT_M_ROOM);
cs.setString(1, room);
ResultSet rs=cs.executeQuery();
if (rs.next()){
// rs.getString(1);
seat_r =rs.getInt(2);
seat_c =rs.getInt(3);
}else{
System.out.println("找不到"+rs.getString(1)+"廳");
System.exit(-1);
}
//此行新增 有空修改
cs=conn.prepareCall(INSTER_SEATS);
for(int i=1;i<=seat_r;i++){
for(int j=1;j<=seat_c;j++){
String sitI=null;
String sitJ=null;
if(i>=0 && i<=9){
sitI="0"+i;
}else
sitI=""+i;
if(j>=0 && j<=9){
sitJ="0"+j;
}else
sitJ=""+j;
cs.setString(1,play.getTimestamp().toString());
cs.setInt(2,play.getMovieNumber());
cs.setString(3, sitI+"-"+sitJ);
cs.setString(4,"0");
cs.setString(5, null);
cs.addBatch();
}
}
cs.executeBatch();
if (conn != null)
conn.close();
}
}
public class Procedure1 {
public static void main(String args[]){
String pt=args[0];
String movie=args[1];
String room=args[2];
MovieSql smt1=new MovieSql();
SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm");
PlaylistVO play=new PlaylistVO();
try{
smt1.setConnection();
Timestamp dateTime=new Timestamp(time.parse(pt).getTime());
play.setPtime(dateTime);
play.setMovidNumber(Integer.parseInt(movie));
play.setRoomid(room);
smt1.insertPalylist(play);
}catch (ParseException e){
System.out.println(e);
}
catch(SQLException e){
System.out.println(e);
}
}
}
以上很多宣告方法還沒用到
沒有留言:
張貼留言