⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 musicsongfiledao.java

📁 本程序是作者开发的一个宽带娱乐系统的一个模块.
💻 JAVA
字号:
package com.singnet.music.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.naming.InitialContext;
import javax.sql.DataSource;

import com.singnet.music.MusicSongFileInfo;

public class MusicSongFileDao {
	public Connection getConnection() throws Exception {
		InitialContext ctx = new InitialContext();
		DataSource ds = (DataSource) ctx.lookup("java:/MySqlDS");
		Connection conn = null;
		Statement stmt = null;
		try {
			conn = ds.getConnection();
		} catch (SQLException sqlEx) {
			System.out.println("Error connect to pool.");
		}
		return conn;
	}

	public boolean addMusicSongFileInfo(MusicSongFileInfo musicSongFileInfo)
			throws Exception {
		Connection conn = null;
		Statement stmt = null;
		boolean re = false;
		String str_sql = "";
		System.out.print(str_sql);
		try {
			conn = getConnection();
			stmt = conn.createStatement();
			stmt.executeUpdate(str_sql);
			re = true;
		} catch (SQLException e) {
			e.printStackTrace();
			re = false;

		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception sqlEx) {
				}
			}
		}
		return re;
	}

	public boolean editMusicSongFileInfo(MusicSongFileInfo musicSongFileInfo)
			throws Exception {
		Connection conn = null;
		Statement stmt = null;
		boolean re = false;
		String str_sql = " ";
		System.out.print(str_sql);
		try {
			conn = getConnection();
			stmt = conn.createStatement();
			stmt.executeUpdate(str_sql);
			re = true;
		} catch (SQLException e) {
			e.printStackTrace();
			re = false;

		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception sqlEx) {
				}
			}
		}
		return re;
	}

	public boolean deleteMusicSongFileInfo(String id) throws Exception {
		Connection conn = null;
		Statement stmt = null;
		boolean re = false;
		String str_sql = "  delete from musicarea where id="+id+" ";
		
		try {
			conn = getConnection();
			stmt = conn.createStatement();
			stmt.executeUpdate(str_sql);
			re = true;
		} catch (SQLException e) {
			e.printStackTrace();
			re = false;

		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception sqlEx) {
				}
			}
		}
		return re;
	}

	public MusicSongFileInfo queryMusicSongFileInfoById(String id) throws Exception {
		Connection conn = null;
		Statement stmt = null;
		MusicSongFileInfo re = new MusicSongFileInfo();
		String str_sql = " select * from musicsongfile where id="+id+"  ";
		ResultSet rs = null;
		System.out.print(str_sql);
		try {
			conn = getConnection();
			stmt = conn.createStatement();
			rs = stmt.executeQuery(str_sql);
			if(rs.next())
			{
				 
				re.setExt(rs.getString("ext"));
			    re.setFilepath(rs.getString("filepath"));
			    re.setHits(rs.getString("hits"));
			    re.setId(rs.getString("id"));
			    re.setLyrics(rs.getString("lyrics"));
			    re.setMark(rs.getString("mark"));
			    re.setName(rs.getString("name"));
			    re.setSingerid(rs.getString("singerid"));
			    re.setVote(rs.getString("vote"));
			    re.setZjid(rs.getString("zjid"));
			    
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception sqlEx) {
				}
			}
		}
		return re;
	}

	public ArrayList queryMusicSongFileInfoByZjid(String zjid) throws Exception {
		Connection conn = null;
		Statement stmt = null;
		ArrayList re = new ArrayList();
		String str_sql = " select * from musicsongfile where zjid="+zjid+"";
		ResultSet rs = null;
		System.out.print(str_sql);
		try {
			conn = getConnection();
			stmt = conn.createStatement();
			rs = stmt.executeQuery(str_sql);
			while(rs.next())
			{
				MusicSongFileInfo m = new MusicSongFileInfo();
			    m.setExt(rs.getString("ext"));
			    m.setFilepath(rs.getString("filepath"));
			    m.setHits(rs.getString("hits"));
			    m.setId(rs.getString("id"));
			    m.setLyrics(rs.getString("lyrics"));
			    m.setMark(rs.getString("mark"));
			    m.setName(rs.getString("name"));
			    m.setSingerid(rs.getString("singerid"));
			    m.setVote(rs.getString("vote"));
			    m.setZjid(rs.getString("zjid"));
			    
				re.add(m);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception sqlEx) {
				}
			}
		}
		return re;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -