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

Listen 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

Understanding Oracle Clinical Understanding Oracle Clinical
by Joan M. Johnson
May 2007
$9.99 USD

Inside SQLite Inside SQLite
by Sibsankar Haldar
April 2007
$9.99 USD

Advertisement
O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com