📄 movie.java
字号:
package com.chapter13;
import java.sql.*;
public class Movie extends ExecuteDB
{
//定义类成员变量
private long MovieID;
private String Name;
private String Intro;
private String Sort;
private String Lang;
private String Addr;
private int Count;
private String Pic;
private String Url;
private String CreateTime;
private String strSql;
//构造函数,对成员变量进行初始化赋值
public Movie()
{
this.MovieID=0;
this.Name="";
this.Intro="";
this.Lang="";
this.Count=0;
this.Pic="";
this.Url="";
this.Addr="";
this.Sort="";
java.util.Date NowTime = new java.util.Date();
this.CreateTime = NowTime.toLocaleString();
this.strSql="";
}
//添加新影片信息,往movies数据表中添加一条新记录
public boolean add()
{
this.strSql="insert into movies ";
this.strSql=this.strSql + "(Name,Intro,Sort,Lang,Addr,Count,Pic,Url,CreateTime)";
this.strSql=this.strSql + "values('" + this.Name + "','" + this.Intro + "','" + this.Sort + "','" + this.Lang + "','" + this.Addr + "','" + this.Count + "','" + this.Pic + "','" + this.Url + "','" + this.CreateTime + "')";
boolean isAdd = super.exeSql(this.strSql);
return isAdd;
}
//删除属于某个集合中的影片信息
public boolean delete(String sMovieID)
{
this.strSql="delete from movies";
this.strSql=this.strSql + " where MovieID in ("+sMovieID+")";
boolean isDelete = super.exeSql(this.strSql);
return isDelete;
}
//获取MovieID对应的影片信息,将这些信息赋值给相应的类变量
public boolean init()
{
this.strSql="select * from `movies` where MovieID=";
this.strSql=this.strSql + "'" + this.MovieID + "'";
try
{
ResultSet rs = super.exeQuery(this.strSql);
if (rs.next())
{
MovieID=rs.getLong("MovieID");
Name=rs.getString("Name");
Intro=rs.getString("Intro");
Lang=rs.getString("Lang");
Addr=rs.getString("Addr");
Count=rs.getInt("Count");
Sort=rs.getString("Sort");
Pic=rs.getString("Pic");
Url=rs.getString("Url");
CreateTime=rs.getString("CreateTime");
return true;
}
else
{
return false;
}
}
catch(Exception e)
{
return false;
}
}
//获得Sort相同的一组影片信息,返回一个ResultSet类型对象
public ResultSet show_sort_movies()
{
this.strSql="select * from `movies`";
this.strSql=this.strSql + " where Sort like '" + this.Sort + "' order by CreateTime desc";
ResultSet rs = null;
try
{
rs = super.exeQuery(this.strSql);
}
catch(Exception e)
{
System.out.println(e.toString());
}
return rs;
}
//获取所有影片信息,它们是按照时间降序排序的,返回一个ResultSet类型对象
public ResultSet show_all_movies()
{
this.strSql="select * from `movies` order by CreateTime desc";
ResultSet rs = null;
try
{
rs = super.exeQuery(this.strSql);
}
catch(Exception e)
{
System.out.println(e.toString());
}
return rs;
}
//按条件搜索影片信息,返回一个ResultSet类型对象
public ResultSet search_movies()
{
this.strSql="select * from `movies` where";
this.strSql = this.strSql + " Name like '%"+this.Name+"%' and";
this.strSql = this.strSql + " Addr like '%"+this.Addr+"%' and";
this.strSql = this.strSql + " Lang like '%"+this.Lang+"%' and";
this.strSql = this.strSql + " Sort like '%"+this.Sort+"%' order by CreateTime desc";
ResultSet rs = null;
try
{
rs = super.exeQuery(this.strSql);
}
catch(Exception e)
{
System.out.println(e.toString());
}
return rs;
}
//修改MovieID对应的影片信息
public boolean modify()
{
this.strSql = "update movies set ";
this.strSql = this.strSql + " Name = '" +this.Name+"',";
this.strSql = this.strSql + " Sort = '" +this.Sort+"',";
this.strSql = this.strSql + " Addr = '" +this.Addr+"',";
this.strSql = this.strSql + " Lang = '" +this.Lang+"',";
this.strSql = this.strSql + " Pic = '" +this.Pic+"',";
this.strSql = this.strSql + " Url = '" +this.Url+"',";
this.strSql = this.strSql + " Intro = '" +this.Intro+"',";
this.strSql = this.strSql + " Count = '" +this.Count+"',";
this.strSql = this.strSql + " CreateTime = '" +this.CreateTime+"'";
this.strSql = this.strSql + " where MovieID =" +this.MovieID;
boolean isModify = super.exeSql(this.strSql);
return isModify;
}
//更改MovieID所对应的Count的值
public boolean modify_Count()
{
this.strSql="update movies set";
this.strSql=this.strSql + " Count = '"+this.Count+"'";
this.strSql=this.strSql + " where MovieID='" + this.MovieID + "'";
boolean isModify = super.exeSql(this.strSql);
return isModify;
}
//设置类成员变量MovieID的值
public void setMovieID(long MovieID)
{
this.MovieID = MovieID;
}
//获取类成员变量MovieID的值
public long getMovieID()
{
return this.MovieID;
}
//设置类成员变量Name的值
public void setName(String Name)
{
this.Name = Name;
}
//获取类成员变量Name的值
public String getName()
{
return this.Name;
}
//设置类成员变量Intro的值
public void setIntro(String Intro)
{
this.Intro = Intro;
}
//获取类成员变量Intro的值
public String getIntro()
{
return this.Intro;
}
//设置类成员变量Sort的值
public void setSort(String Sort)
{
this.Sort = Sort;
}
//获取类成员变量Sort的值
public String getSort()
{
return this.Sort;
}
//设置类成员变量Lang的值
public void setLang(String Lang)
{
this.Lang = Lang;
}
//获取类成员变量Lang的值
public String getLang()
{
return this.Lang;
}
//设置类成员变量Addr的值
public void setAddr(String Addr)
{
this.Addr = Addr;
}
//获取类成员变量Addr的值
public String getAddr()
{
return this.Addr;
}
//设置类成员变量CreateTime的值
public void setCreateTime(String CreateTime)
{
this.CreateTime = CreateTime;
}
//获取类成员变量CreateTime的值
public String getCreateTime()
{
return this.CreateTime;
}
//设置类成员变量Count的值
public void setCount(int Count)
{
this.Count = Count;
}
//获取类成员变量Count的值
public int getCount()
{
return this.Count;
}
//设置类成员变量Pic的值
public void setPic(String Pic)
{
this.Pic = Pic;
}
//获取类成员变量Pic的值
public String getPic()
{
return this.Pic;
}
//设置类成员变量Url的值
public void setUrl(String Url)
{
this.Url = Url;
}
//获取类成员变量Url的值
public String getUrl()
{
return this.Url;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -