package control.bean; /** * @管理歌曲 * */ import java.sql.CallableStatement; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Vector; import model.MusicModel; import control.DataBaseConnector; public class ManageMusic { private Connection con; private DataBaseConnector db; /** * 构造函数 */ public ManageMusic(){ db = new DataBaseConnector(); } /** * 分页 * */ public Vector displayQuery(int noteperpage,int pagecode, String condition,String keyfield) throws SQLException{ con = db.getConnection(); CallableStatement cst = null; String query = "{call sp_getpage(?,?,?,?)}"; Vector musicvector = null; try{ cst = con.prepareCall(query); cst.setInt(1,noteperpage); cst.setInt(2,pagecode); cst.setString(3,condition); cst.setString(4,keyfield); ResultSet rs = cst.executeQuery(); musicvector = new Vector(); while(rs.next()) { MusicModel musicmodel = new MusicModel(); musicmodel.setMusicid(rs.getInt(1)); musicmodel.setMusicName(rs.getString(2)); musicmodel.setMusicType(rs.getString(3)); musicmodel.setSingerName(rs.getString(4)); musicmodel.setSubmitime(rs.getDate(5)); musicvector.add(musicmodel); } }catch(SQLException e){ e.getMessage(); } if(con!=null) con.close(); return musicvector; } /** * 返回表的总行数 */ public int getTotalrow() throws SQLException{ con = db.getConnection(); PreparedStatement pst = null; String query = "select count(*) from MusicInfo"; int totalrow = 0; try{ pst = con.prepareStatement(query); ResultSet rs = pst.executeQuery(); while(rs.next()){ totalrow = rs.getInt(1); } }catch(SQLException e){ e.getMessage(); } if(con!=null) con.close(); return totalrow; } /** * 修改歌曲 */ public int updateMusic(int musicid,String musicname,String musictype, String singername) throws SQLException{ con = db.getConnection(); PreparedStatement pst = null; String update = "update MusicInfo set MusicName=?,MusicType=?,SingerName=? where MusicID = ?"; int rowaffect = 0; try{ pst = con.prepareStatement(update); pst.setString(1,musicname); pst.setString(2,musictype); pst.setString(3,singername); pst.setInt(4,musicid); rowaffect = pst.executeUpdate(); }catch(SQLException e){ e.getMessage(); } if(con!=null){ con.close(); } return rowaffect; } /** * 删除歌曲 * */ public int deleteMusic(int musicid)throws SQLException{ con = db.getConnection(); PreparedStatement pst = null; String delete = "delete from MusicInfo where MusicID = ?"; int rowaffect = 0; try{ pst = con.prepareStatement(delete); pst.setInt(1,musicid); rowaffect = pst.executeUpdate(); }catch(SQLException e){ e.getMessage(); } if(con!=null){ con.close(); } return rowaffect; } }
最近下载更多
永远滴神YY LV1
2023年4月17日
15256894279 LV2
2022年2月23日
李拾壹 LV5
2022年1月2日
wanglinddad LV54
2021年12月19日
3089559272 LV11
2021年12月17日
木木不爱安妮酱 LV10
2021年11月5日
白嫖的QQQ LV1
2021年10月21日
Administrator LV3
2021年6月26日
Jack何 LV1
2021年6月22日
wangyumiao LV3
2021年6月1日
最近浏览更多
a2831244768 LV4
4月13日
asddwh LV12
2023年12月26日
蹇金金 LV7
2023年11月7日
1790759671
2023年11月1日
暂无贡献等级
julang
2023年10月11日
暂无贡献等级
2036495585 LV9
2023年9月18日
543539666 LV7
2023年8月30日
zhangwuxuan
2023年7月15日
暂无贡献等级
Llllll153
2023年7月9日
暂无贡献等级
komice1992 LV3
2023年7月1日