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

📄 musicmodel.java~14~

📁 音乐播放器 好像是用java编的 欢迎下载
💻 JAVA~14~
字号:
package musicmgrsys;

import java.util.Observable;
import java.sql.*;
import javax.swing.JOptionPane;

public class MusicModel extends Observable {
    private String tabname = null;
    private boolean s_open = false;
    private boolean c_open = false;
    private Statement stmt = null;
    private Connection con = null;

    public MusicModel(String tabname) {
        this.tabname = tabname;
    }

    public String getTabname()
    {
        return this.tabname;
    }

    public Statement getStatement()
    {
        return this.stmt;
    }

    public Connection getConnection()
    {
        return this.con;
    }

    public void connectDB()
    {
        String DRIVER = "com.borland.datastore.jdbc.DataStoreDriver";
        String URL = "jdbc:borland:dslocal:";
        String FILE = "musicmgrsys.jds";

        try
        {
            Class.forName(DRIVER);
            con = DriverManager.getConnection(URL + FILE, "SYSDBA", "masterkey");
            c_open = true;

            stmt = con.createStatement();
            s_open = true;
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, e.toString());
        }
    }

    public void closeDB()
    {
        try
        {
            if(s_open)
            {
                stmt.close();
                s_open = false;
            }
        }
        catch(Exception e1)
        {
            JOptionPane.showMessageDialog(null, e1.toString());
        }

        try
        {
            if(c_open)
            {
                con.close();
                c_open = false;
            }
        }
        catch(Exception e2)
        {
            JOptionPane.showMessageDialog(null, e2.toString());
        }
    }

    public void addMusic(Music music)
    {
        String sql = "insert into " + tabname + "values('" + music.getFormat()
                     + "', '" + music.getGerue() + "', " + music.getRating()
                     + ", '" + music.getEvaluation() + "', '" + music.getTitle()
                     + "', '" + music.getDirector() + "', " + music.getYear()
                     + ", '" + music.getComments() + "')";

        if((c_open == true) && (s_open == true))
        {
            try
            {
                stmt.executeUpdate(sql);
                setChanged();
                notifyObservers();
            }
            catch(Exception e)
            {
                JOptionPane.showMessageDialog(null, e.toString());
            }
        }
        else
            return;
    }

    public void delMusic(String title)
    {
        String sql = "delete from " + tabname + "where TITLE=" + title;

        if((c_open == true) && (s_open == true))
        {
            try
            {
                stmt.executeUpdate(sql);
                setChanged();
                notifyObservers();
            }
            catch(Exception e)
            {
                JOptionPane.showMessageDialog(null, e.toString());
            }
        }
        else
            return;

    }

    public void editMusic(String title, Music music)
    {
        delMusic(title);
        addMusic(music);
    }
}


⌨️ 快捷键说明

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