O'Reilly Databases

oreilly.comSafari Books Online.Conferences.

We've expanded our coverage and improved our search! Search for all things Database across O'Reilly!

Search Search Tips

advertisement
AddThis Social Bookmark Button

Print Subscribe to Newsletters

SQLJ, the Oracle JVM, and Enterprise JavaBeans: Example

[ Back to Article ]
/*
   The program Client.java illustrates how to use the
   Customer bean.
*/

// import the Customer bean classes
import customer.Customer;
import customer.CustomerHome;
import customer.CustomerRecord;

// import the Java Naming and Directory Interface classes
import oracle.aurora.jndi.sess_iiop.ServiceCtx;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

// import java.sql.Date (required for the dob attribute)
import java.sql.Date;

public class Client {

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

    // get the arguments from the command line
    if (args.length != 4) {
      System.out.println("usage: Client service_URL bean_name " +
        "username password");
      System.exit(1);
    }
    String service_URL = args[0];
    String bean_name = args[1];
    String username = args[2];
    String password = args[3];

    // initialize the Java Naming and Directory Interface (JNDI)
    // environment so that the Client program can run the Customer bean
    Hashtable env = new Hashtable();
    env.put(Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    env.put(Context.SECURITY_PRINCIPAL, username);
    env.put(Context.SECURITY_CREDENTIALS, password);
    env.put(Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    Context ic = new InitialContext(env);

    // create a CustomerHome object and use the lookup() method to
    // locate the Customer bean
    CustomerHome customer_home = (CustomerHome) ic.lookup(service_URL +
      bean_name);

    // create a Customer object and call the create() method to create
    // an instance of the Customer bean
    Customer customer_bean = customer_home.create();

    // create a CustomerRecord object and set it to the row returned
    // from the getRow() method contained in the Customer bean
    CustomerRecord customer_record = customer_bean.getRow(1);

    // display the CustomerRecord attributes
    System.out.println("Customer Information:");
    System.out.println("id = " + customer_record.id);
    System.out.println("first_name = " + customer_record.first_name);
    System.out.println("last_name = " + customer_record.last_name);
    System.out.println("dob = " + customer_record.dob);
    System.out.println("phone = " + customer_record.phone);
  }
}

[ Back to Article ]


Tagged Articles

Be the first to post this article to del.icio.us

Sponsored Resources

  • Inside Lightroom

Related to this Article

Big Data Now: Current Perspectives from O'Reilly Radar Big Data Now: Current Perspectives from O'Reilly Radar
by O'Reilly Radar Team
August 2011
$0.00 USD

Professional NoSQL Professional NoSQL
August 2011
$29.99 USD

Advertisement
Sign up today to receive special discounts,
product alerts, and news from O'Reilly.
Privacy Policy >
View Sample Newsletter >
  • Youtube
  • http://www.youtube.com/OreillyMedia
  • Twitter
  • Subscribe
  • View All RSS Feeds >
O'Reilly Media

800-889-8969 or 707-827-7019
Monday-Friday 7:30am-5pm PT
©2011, O'Reilly Media, Inc.
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
  • About O'Reilly
  • Academic Solutions
  • Contacts
  • Customer Service
  • Careers
  • Press Room
  • Privacy Policy
  • Terms of Service
  • Writing for O'Reilly
  • Community
  • Authors
  • Forums
  • Membership
  • Newsletters
  • RSS Feeds
  • User Groups
  • More O'Reilly Sites
  • igniteshow.com
  • makerfaire.com
  • makezine.com
  • craftzine.com
  • labs.oreilly.com
  • Partner Sites
  • PayPal Developer Zone
  • O'Reilly Insights on Forbes.com