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

📄 musicclient.java

📁 软件开发技术与方法
💻 JAVA
字号:
package musicstore;

import java.rmi.RemoteException;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import musicstore.*;


public class MusicClient {

    public static void main(String[] args) {
        Context     c    = null;
        MusicCDHome home = null;
        MusicCD     cd   = null, cd2 = null;
        try {
            c = new InitialContext();
        }
        catch (NamingException e) {
            System.out.println("Can't get context.");
        }
        try {
            Object obj = c.lookup("ejb/MusicCD");
            home = (MusicCDHome) PortableRemoteObject.narrow(obj, MusicCDHome.class);
        }
        catch (Exception e) {
            System.out.println("Can't look up MusicCDHome.");
        }
        //
        // put your favorite CD here (see 'music.barnesandnoble.com'):
        //
        try {
            cd = home.create("743214270996");
        }
        catch (Exception e) {
            System.out.println("Can't create new CD.");
            System.out.println(e);
            e.printStackTrace();
        }
        try {
            cd.setTitle("Apache Indian");
            cd.setArtist("Apache Indian");
            cd.setType("Bhangra Rap");
            cd.setPrice((float) 12.58);
        }
        catch (RemoteException e) {
            System.out.println("Can't update new CD.");
            e.printStackTrace();
        }
        try {
		String mykey="743214270996";
            cd2 = home.findByPrimaryKey(mykey);
            System.out.println("Title: "  + cd2.getTitle());
            System.out.println("Artist: " + cd2.getArtist());
            System.out.println("Type: "   + cd2.getType());
            System.out.println("Price: "  + cd2.getPrice());
        }
        catch (Exception e) {
            System.out.println("Can't access new CD by primary key.");
            e.printStackTrace();
        }
    }
}

⌨️ 快捷键说明

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