musicbbs.zip

  • nnikaa
    了解作者
  • Java
    开发工具
  • 12.2MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2021-03-13 21:37
    上传日期
一个网页版音乐播放器,可注册用户设置密码有随机验证码上传歌曲试听加入歌单查看最近播放等。页面可自行更换优化。
musicbbs.zip
内容介绍
package dao; import model.Muser; import model.Music; import model.Ugroup; import util.DBTool; import java.rmi.activation.UnknownGroupException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; public class UgroupDao { //显示我的歌单 public List<Ugroup> getList2(String uname){ Connection connection = DBTool.getConnetion(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; List<Ugroup> list = new ArrayList<>(); Ugroup ugroup = null; try { String sql = "select ugroup.id,ugroup.name" + " from ugroup where uname=? and name not in (select name from mgroup where id=2)"; // 获取语句对象,用于将sql语句发送到mysql去执行 preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, uname); // 执行SQL语句并返回结果---查询到的一行行记录(0-N) resultSet = preparedStatement.executeQuery(); // while (resultSet.next()){ ugroup = new Ugroup(); ugroup.setId(resultSet.getInt(1)); ugroup.setName(resultSet.getString(2)); list.add(ugroup); } } catch (SQLException e) { e.printStackTrace(); } finally { // 关闭资源 DBTool.close(connection); } return list; } //初始化歌单 public int init(String uname){ Connection connection = DBTool.getConnetion(); PreparedStatement preparedStatement = null; int resultSet = 0; Muser userinfo = null; try { String sql = "insert into ugroup(uname,name) select '"+uname+"',name from mgroup order by id"; // 获取语句对象,用于将sql语句发送到mysql去执行 preparedStatement = connection.prepareStatement(sql); // 执行SQL语句并返回结果---查询到的一行行记录(0-N) resultSet = preparedStatement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { // 关闭资源 DBTool.close(connection); } return resultSet; } //显示我的歌单 public List<Ugroup> getList(String uname){ Connection connection = DBTool.getConnetion(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; List<Ugroup> list = new ArrayList<>(); Ugroup ugroup = null; try { String sql = "select ugroup.id,ugroup.name,COUNT( DISTINCT umusic.mid),ifnull((select 1 from mgroup where mgroup.name =ugroup.name ),0) " + " from ugroup LEFT JOIN umusic on ugroup.id=umusic.gid where uname=? " + " group by ugroup.id,ugroup.name"; // 获取语句对象,用于将sql语句发送到mysql去执行 preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, uname); // 执行SQL语句并返回结果---查询到的一行行记录(0-N) resultSet = preparedStatement.executeQuery(); // while (resultSet.next()){ ugroup = new Ugroup(); ugroup.setId(resultSet.getInt(1)); ugroup.setName(resultSet.getString(2)); ugroup.setCount(resultSet.getInt(3)); int mod = resultSet.getInt(4); if(mod==1){ ugroup.setMod(false); }else{ ugroup.setMod(true); } list.add(ugroup); } } catch (SQLException e) { e.printStackTrace(); } finally { // 关闭资源 DBTool.close(connection); } return list; } //新增歌单分组 public int add(Ugroup ugroup){ Connection connection = DBTool.getConnetion(); PreparedStatement preparedStatement = null; int resultSet = 0; try { String sql = "insert into ugroup(uname,name ) value (?,?)"; // 获取语句对象,用于将sql语句发送到mysql去执行 preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, ugroup.getUname()); preparedStatement.setString(2, ugroup.getName()); // 执行SQL语句并返回结果---查询到的一行行记录(0-N) resultSet = preparedStatement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { // 关闭资源 DBTool.close(connection); } return resultSet; } //修改歌单名字 public int mod(Ugroup ugroup){ Connection connection = DBTool.getConnetion(); PreparedStatement preparedStatement = null; int resultSet = 0; try { String sql = "update ugroup set name=? where id=? and uname=?"; // 获取语句对象,用于将sql语句发送到mysql去执行 preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, ugroup.getName()); preparedStatement.setInt(2, ugroup.getId()); preparedStatement.setString(3, ugroup.getUname()); // 执行SQL语句并返回结果---查询到的一行行记录(0-N) resultSet = preparedStatement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { // 关闭资源 DBTool.close(connection); } return resultSet; } //删除歌单 public int del(int gid,String uname){ Connection connection = DBTool.getConnetion(); PreparedStatement preparedStatement = null; int resultSet = 0; try { String sql = "delete from ugroup where uname=? and id=? "; // 获取语句对象,用于将sql语句发送到mysql去执行 preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, uname); preparedStatement.setInt(2,gid); // 执行SQL语句并返回结果---查询到的一行行记录(0-N) resultSet = preparedStatement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { // 关闭资源 DBTool.close(connection); } return resultSet; } //获取单个歌单信息 public Ugroup get(int id){ Connection connection = DBTool.getConnetion(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; Ugroup ugroup = null; try { String sql = "select id,name,uname from ugroup where id=? "; // 获取语句对象,用于将sql语句发送到mysql去执行 preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, id); // 执行SQL语句并返回结果---查询到的一行行记录(0-N) resultSet = preparedStatement.executeQuery(); // while (resultSet.next()){ ugroup = new Ugroup(); ugroup.setId(resultSet.getInt(1)); ugroup.setName(resultSet.getString(2)); ugroup.setUname(resultSet.getString(3)); break; } } catch (SQLException e) { e.printStackTrace(); } finally {
评论
    相关推荐