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

📄 studentbmpclient.java

📁 J2EE开发与Weblogic一书中的源代码
💻 JAVA
字号:
package com.learnweblogic.examples.ch9.bmp;

import com.learnweblogic.examples.BaseClient;

import javax.ejb.DuplicateKeyException;
import javax.naming.NamingException;
import java.rmi.RemoteException;

public final class StudentBMPClient extends BaseClient {

  private StudentHome studentHome;

  public StudentBMPClient(String [] argv) 
    throws NamingException
  {
    super(argv);
    
    try {
      studentHome = (StudentHome) 
        narrow(getInitialContext().lookup("StudentEJB"), StudentHome.class);

    } catch (NamingException ne) {
      System.err.println("Unable to lookup EJB: StudentEJB");
      System.err.println("Please make sure that you have deployed this EJB.");
      throw ne;
    }
  }

  private void runExample()
    throws Exception
  {
    Student s = null;

    try {
      s = studentHome.create("John Doe", 200, 10);
      System.err.println("Created a John Doe Student BMP Entity.");

    } catch (DuplicateKeyException dke) {
      System.err.println("Student named John Doe already exists.");
      System.err.println("Remove the John Doe bean from your "+
        "database table and re-run the example.");
      throw dke;
    } catch (Exception e) {
      System.err.println("Unable to create Student bean.");
      System.err.println("");
      System.err.println("Did you create the database tables?");
      System.err.println("");
      System.err.println("");
      throw e;
    }

    try {
      s.setGrade(4);
      
      System.err.println("Changed student's grade to 4.");
    } catch (RemoteException re) {
      System.err.println("Unable to update student's grade.");
      re.printStackTrace();
      throw re;
    }

    try {
      s.remove();

    } catch (Exception e) {
      System.err.println("Unable to remove Student bean.");
      e.printStackTrace();
      throw e;
    }
  }

  public static void main(String[] argv) 
    throws Exception
  {

    System.err.println("");
    System.err.println("Running StudentBMPClient.....");
    System.err.println("");

    StudentBMPClient sc = new StudentBMPClient(argv);

    sc.runExample();

    System.err.println("");

  }
}

⌨️ 快捷键说明

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