📄 videoinformationdao.java
字号:
package cn.myvideosite.data.model.dao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import cn.myvideosite.data.model.bean.VideoInformation;
public class VideoInformationDAO extends BaseDAO {
/**
* 视频信息表的保存方法
* @param videoinformation
* @return
*/
public static VideoInformation save(VideoInformation videoinformation){
PreparedStatement pstmt=null;
String sql="insert into videoinformation (userId,uploadTime,videoTiTle,flowerNub,channelId,introduction,flashAddress,ding,score,soureUrl,newUrl,headTitle) values (?,?,?,?,?,?,?,?,?,?,?,?)";
try {
pstmt=connection.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
pstmt.setInt(1,videoinformation.getUserId());
pstmt.setTimestamp(2,new Timestamp(videoinformation.getUploadTime().getTime()));
pstmt.setString(3, videoinformation.getVideoTitle());
pstmt.setInt(4, videoinformation.getFlowerNub());
pstmt.setInt(5,videoinformation.getChannelId());
pstmt.setString(6,videoinformation.getIntroduction());
pstmt.setString(7,videoinformation.getFlashAddress());
pstmt.setInt(8,videoinformation.getDing());
pstmt.setInt(9,videoinformation.getScore());
pstmt.setString(10,videoinformation.getSoureUrl());
pstmt.setString(11,videoinformation.getNewUrl());
pstmt.setString(12,videoinformation.getHeadTitle());
if(pstmt.executeUpdate()==1){
ResultSet rs=pstmt.getGeneratedKeys();
if(rs!=null){
rs.next();
videoinformation.setVideoId(rs.getInt(1));
}
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
if(pstmt!=null){
try {
pstmt.close();
pstmt=null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return videoinformation;
}
/**
* 视频信息表删除方法
* @param id
*/
public static void delete(int videoId){
PreparedStatement pstmt=null;
String sql="delete from videoinformation where videoId=?";
try {
pstmt=connection.prepareStatement(sql);
pstmt.setInt(1, videoId);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
if(pstmt!=null){
pstmt.close();
pstmt=null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/**
* 视频信息表更新方法
* @param videoinformation
*/
public static void update(VideoInformation videoinformation){
PreparedStatement pstmt=null;
String sql="update videoinformation set userId=?,uploadTime=?,videoTiTle=?,flowerNub=?,channelId=?,introduction=?,flashAddress=?,ding=?,score=?,soureUrl=?,newUrl=?,headTitle=? where videoId=?";
try {
pstmt=connection.prepareStatement(sql);
pstmt.setInt(1, videoinformation.getUserId());
pstmt.setTimestamp(2,new Timestamp(videoinformation.getUploadTime().getTime()));
pstmt.setString(3, videoinformation.getVideoTitle());
pstmt.setInt(4, videoinformation.getFlowerNub());
pstmt.setInt(5,videoinformation.getChannelId());
pstmt.setString(6,videoinformation.getIntroduction());
pstmt.setString(7,videoinformation.getFlashAddress());
pstmt.setInt(8,videoinformation.getDing());
pstmt.setInt(9,videoinformation.getScore());
pstmt.setString(10,videoinformation.getSoureUrl());
pstmt.setString(11,videoinformation.getNewUrl());
pstmt.setString(12,videoinformation.getHeadTitle());
pstmt.setInt(13, videoinformation.getVideoId());
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
if(pstmt!=null){
pstmt.close();
pstmt=null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/**
* 视频信息表查询单条记录
* @param id
* @return
*/
public static VideoInformation findById(int VideoId){
PreparedStatement pstmt=null;
ResultSet rs=null;
VideoInformation videoinformation=null;
String sql="select * from videoinformation where VideoId=?";
try {
pstmt=connection.prepareStatement(sql);
pstmt.setInt(1,VideoId);
rs=pstmt.executeQuery();
videoinformation =new VideoInformation();
while(rs.next()){
videoinformation.setVideoId(rs.getInt(1));
videoinformation.setUserId(rs.getInt(2));
videoinformation.setUploadTime(rs.getTimestamp(3));
videoinformation.setVideoTitle(rs.getString(4));
videoinformation.setFlowerNub(rs.getInt(5));
videoinformation.setChannelId(rs.getInt(6));
videoinformation.setIntroduction(rs.getString(7));
videoinformation.setFlashAddress(rs.getString(8));
videoinformation.setDing(rs.getInt(9));
videoinformation.setScore(rs.getInt(10));
videoinformation.setSoureUrl(rs.getString(11));
videoinformation.setNewUrl(rs.getString(12));
videoinformation.setHeadTitle(rs.getString(13));
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
try {
if(rs!=null){
rs.close();
rs=null;
}
if(pstmt!=null){
pstmt.close();
pstmt=null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return videoinformation;
}
/**
* 视频信息表查询全部 无参数的方法
* @return
*/
public static List<VideoInformation> findAll(){
PreparedStatement pstmt=null;
ResultSet rs=null;
List<VideoInformation> rtnList=null;
String sql="select * from videoinformation";
try {
pstmt=connection.prepareStatement(sql);
rs=pstmt.executeQuery();
rtnList=new ArrayList<VideoInformation>();
while(rs.next()){
VideoInformation videoinformation=new VideoInformation();
videoinformation.setVideoId(rs.getInt(1));
videoinformation.setUserId(rs.getInt(2));
videoinformation.setUploadTime(rs.getTimestamp(3));
videoinformation.setVideoTitle(rs.getString(4));
videoinformation.setFlowerNub(rs.getInt(5));
videoinformation.setChannelId(rs.getInt(6));
videoinformation.setIntroduction(rs.getString(7));
videoinformation.setFlashAddress(rs.getString(8));
videoinformation.setDing(rs.getInt(9));
videoinformation.setScore(rs.getInt(10));
videoinformation.setSoureUrl(rs.getString(11));
videoinformation.setNewUrl(rs.getString(12));
videoinformation.setHeadTitle(rs.getString(13));
rtnList.add(videoinformation);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
if(rs!=null){
rs.close();
rs=null;
}
if(pstmt!=null){
pstmt.close();
pstmt=null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return rtnList;
}
/**
* 视频信息表的查询全部 有参数的方法
* @param first
* @param max
* @return
*/
public static List<VideoInformation> findAll(int first,int max){
PreparedStatement pstmt=null;
ResultSet rs=null;
List<VideoInformation> rtnList=null;
String sql="select * from videoinformation limit ?,?";
try {
pstmt=connection.prepareStatement(sql);
pstmt.setInt(1, first);
pstmt.setInt(2,max);
rs=pstmt.executeQuery();
rtnList=new ArrayList<VideoInformation>();
while(rs.next()){
VideoInformation videoinformation=new VideoInformation();
videoinformation.setVideoId(rs.getInt(1));
videoinformation.setUserId(rs.getInt(2));
videoinformation.setUploadTime(rs.getTimestamp(3));
videoinformation.setVideoTitle(rs.getString(4));
videoinformation.setFlowerNub(rs.getInt(5));
videoinformation.setChannelId(rs.getInt(6));
videoinformation.setIntroduction(rs.getString(7));
videoinformation.setFlashAddress(rs.getString(8));
videoinformation.setDing(rs.getInt(9));
videoinformation.setScore(rs.getInt(10));
videoinformation.setSoureUrl(rs.getString(11));
videoinformation.setNewUrl(rs.getString(12));
videoinformation.setHeadTitle(rs.getString(13));
rtnList.add(videoinformation);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
if(rs!=null){
rs.close();
rs=null;
}
if(pstmt!=null){
pstmt.close();
pstmt=null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return rtnList;
}
/**
* 判断视频的地址得唯一性
*/
public static VideoInformation findByFlashAddr(String flashAddress){
PreparedStatement pstmt=null;
ResultSet rs=null;
VideoInformation videoinformation=null;
String sql="select * from videoinformation where flashAddress=?";
try {
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, flashAddress);
rs=pstmt.executeQuery();
if(rs.next()){
videoinformation=new VideoInformation();
videoinformation.setVideoId(rs.getInt(1));
videoinformation.setUserId(rs.getInt(2));
videoinformation.setUploadTime(rs.getTimestamp(3));
videoinformation.setVideoTitle(rs.getString(4));
videoinformation.setFlowerNub(rs.getInt(5));
videoinformation.setChannelId(rs.getInt(6));
videoinformation.setIntroduction(rs.getString(7));
videoinformation.setFlashAddress(rs.getString(8));
videoinformation.setDing(rs.getInt(9));
videoinformation.setScore(rs.getInt(10));
videoinformation.setSoureUrl(rs.getString(11));
videoinformation.setNewUrl(rs.getString(12));
videoinformation.setHeadTitle(rs.getString(13));
}
} catch (SQLException e) {
e.printStackTrace();
}
return videoinformation;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -