📄 songclient.java
字号:
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.ejb.*;
import java.sql.*;
public class SongClient
{
private String iSong_id,cSong_name,iArtist_code,cLink;
SongHome home;
Song remote;
public String getiSong_code()
{
return iSong_id;
}
public String getcSong_name()
{
return cSong_name;
}
public String getiArtist_code()
{
return iArtist_code;
}
public String getcLink()
{
return cLink;
}
public void setiSong_id(String iSong_id)
{
this.iSong_id=iSong_id;
}
public void setcSong_name(String cSong_name)
{
this.cSong_name=cSong_name;
}
public void setiArtist_code(String iArtist_code)
{
this.iArtist_code=iArtist_code;
}
public void setcLink(String cLink)
{
this.cLink=cLink;
}
public SongClient()throws SQLException
{
try
{
Context init=new InitialContext();
Object obj=init.lookup("Song");
home=(SongHome)PortableRemoteObject.narrow(obj,SongHome.class);
}
catch(Exception e)
{
throw new SQLException(e.toString());
}
}
public String createEvent()throws SQLException
{
String Message="";
try
{
remote=home.create(iSong_id,cSong_name,iArtist_code,cLink);
Message="the Song has created";
}
catch(DuplicateKeyException dupex)
{
Message="the code"+iSong_id+" has been in the DataBase";
System.out.println(dupex.toString());
}
catch(Exception e)
{
System.out.println(e.toString());
}
return Message;
}
public String updateEvent()
{
String Message="";
try
{
remote=home.findByPrimaryKey(iSong_id);
remote.updateSong(iSong_id,cSong_name,iArtist_code,cLink);
Message="Successful!you have updated the song details.";
}
catch(Exception e)
{
Message="Modify Failed";
System.out.println(e.toString());
}
return Message;
}
public String deleteEvent()
{
String Message="";
try
{
remote=home.findByPrimaryKey(iSong_id);
remote.remove();
Message="Delete Successfully!";
}
catch(Exception e)
{
Message="Cannot find the code!";
System.out.println(e.toString());
}
return Message;
}
public Vector findEvent()
{
String Message="";
Vector v=new Vector();
try
{
remote=home.findByPrimaryKey(iSong_id);
String st=remote.getSongid();
String str=remote.getSongname();
String stri=remote.getArtistcode();
String strin=remote.getSonglink();
v.addElement(st);
v.addElement(str);
v.addElement(stri);
v.addElement(strin);
Message="Result by searching ID";
}
catch(Exception e)
{
Message="invalid ID,please check your ID";
System.out.println(e.toString());
}
return v;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -