★ wanayoo — archive 1999 http://javaboutique.internet.com/Map_Java_Objects/index-8.htmlNouvelle recherche | Portail wanayoo
Attend Be an Exhibitor Be a Sponsor

Aligning Measurement and Business Goals

www.searchenginewatch.com


Find a Web Host With:
CGI Access
DB Support
NT Servers
UNIX Servers
Telnet Access

advanced search
Internet News
Internet Investing
IT
Windows Technology
Linux/Open Source
Developer
Interactive Marketing
xSP Resources
Small Business
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertise
Corporate Info
Newsletters
E-mail Offers
Be a Commerce Partner
Tech Magazines - FREE
Digital Camera Reviews
MLM Training
Internet Jobs
Find a Web HostFind a Web Host
Internet Monitoring
Build Flash Online
MLM Leads
Email Management
Compare Prices & Shop
FlashKit
Gif.com
HierMenusCentral
JavaBoutique
JavaScript.com
JavaScriptSource
WebDev Jobs
JustSMIL
ScriptSearch
StreamingMediaWorld
Web Hosts
WebDevelopersJournal WDVL
WebDeveloper.com
WebReference.com
XMLFiles.com
CGI
HTML
Java
JavaScript
Web Design and Promotion
Web Site Development
E-mail Address:


Can you receive
HTML e-mail?

Yes   No

Zip Code:



Reviews :

Mapping Java Objects to a Database with Castor-JDO:

Reading from the database

Having data in the media, movie, and actor tables we'll now see how easy it is to create objects with data from the database. Assume that we want to find all movies where Keanu Reeves is an actor. The only thing we need to get started is to query his name, and magic happens: all objects are ready to use. The next program lists the movies and the medias where Keanu Reeves appears:

package hansen.playground;
import org.exolab.castor.jdo.*;
import java.util.*;

public class ReadActor {
  public static void main(String[] args) {
    try {
      // Define the JDO object
      JDO jdo = new JDO("mydb"); 
      jdo.setConfiguration("database.xml"); 

      // Open a connection to the database
      Database db = jdo.getDatabase();
      
      // Begin a transaction
      db.begin(); 
      
      OQLQuery query; 
      QueryResults results; 
      query = db.getOQLQuery(
        "SELECT a FROM hansen.playground.Actor a WHERE a.name=$1");
      query.bind("Keanu Reeves");  
      results = query.execute(Database.ReadOnly);
      Actor actor = (Actor)results.next();
      
      System.out.println("Actor: " + actor.getName());
      Collection movies = actor.getMovies();
      for (Iterator it = movies.iterator(); it.hasNext();) {
        Movie movie = (Movie)it.next();
        System.out.println("Movie: " + movie.getTitle());
        Media media = movie.getMedia();
        System.out.println("Media: " + media.getType());
      }  

      // Commit the transaction
      db.commit(); 
      db.close(); 

    } catch (PersistenceException e) {
      e.printStackTrace(); 
    }  
  }
}

- Listing 8: Reading from the database -

The output from the program is this:

Actor: Keanu Reeves
Movie: The Matrix
Media: DVD
Movie: Chain Reaction
Media: VHS

The execute method specifies "readonly", since we're not updating any data. There might be a performance gain in doing this.


Applet Index
(sorted alphabetically)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z #s
The Java Source
(applets w/source code)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z

How to Add Java Applets to Your Site

New on the Java Boutique:

New Article:
Java Development Tools You Never Knew Existed
The world of software is ever-growing, and though we all like to stay on top of all the tools available to us, who has the time? Well Drew Falkman took the time to bring you his five favorite tools you didn't know existed.
... [more articles]

New Tutorial:
Mapping Java Objects to a Database with Castor-JDO
Looking to be more productive? Who isn't? Keld introduces us to Castor-JDO, a tool that will enthrall you with its simplicity. If you have a simple data model, and are fonder of Java coding than SQL coding, then Castor can help you to be more productive.
... [more Tutorials]

Year in Review:
The Best of 2002
The year 2002 saw 201 new applets posted to JavaBoutique. Check out the 2 most popular apps from each month of 2002!
... [popular applets]

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

internet.com logo


WebDev News

Sun Spells P2P: JXTA

Now Complete, Grid Computing Spec is Proposed

Sendmail, Beware



Database Journal Launched!
Jupiter Media has announced the launch of Database Journal. DBJ offers SQL courses and other database related resources for beginner to expert developers.



Jftp v1.0 (Java Upload Applet)
Jftp provides you with the ease of uploading files over the internet via FTP from within your very own web enabled applications.
Download of the Week
bdLCD
bdLCD is a Java applet that looks like a realistic LCD panel using a typical 5x7 character set.

JB User Poll
How do you get the majority of your programming questions answered?
The JavaBoutique Top 15:
1. ChompText
2. NavBar
3. DJPopMenu
4. PingPong
5. Distorter
6. RushHour
7. Encyclo
8. AnimLetters_anim
9. PulseText
10. AScroll2
11. Nibbly
12. BMMenu
13. BMI
14. Viewer
15. Jtimer
Want more? Check out our Top 100!

Refer-It
Affiliate Program and Referral Directory.
New on internet.com
Library Porn Filter Law Hits High Court
Supreme Court to decide if Children's Internet Protection Act is a violation of the First Amendment.

Shoppers Utilize Multi-Channel Choices
More than half of the 2002 holiday consumers utilized a combination of shopping sources, and research finds that these multi-channel shoppers are the most valuable.

The Worm That Won't Go Away
A variant of the Klez worm not only was the most frequently occurring worm for the month of February, it's become the most persistent worm ever.


Aligning Measurement and Business Goals

Copyright 2003 Jupitermedia Corporation All Rights Reserved.
Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.internet.com/