📄 musicmodel.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 + -