★ wanayoo — archive 1999 http://javaboutique.webdeveloper.com/Map_Java_Objects/index-3.htmlNouvelle recherche | Portail wanayoo
Computer Digital Expo

100's of firms that help your Web site be found


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
Promote Your Website
Free Market Research
Hacker's Secrets
Internet Jobs
Top Selling Books
Software Licenses
Shop Digital Cameras
Best Deals on PDAs!
Shop For Computers
Find a Web Host
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:

Installation of Castor-JDO

To get a head start we'll also start by downloading Castor from this address: http://castor.exolab.org/download.html. Select the link "The Castor JARs, docs, DTDs, command line tools and examples". It'll give you the jar-files for both Castor-JDO and Castor-XML, documentation (including javadoc) and a few examples. Unzip the files, locate the Castor-JDO jar file (mine is called castor-0.9.4.3.jar), put it in you classpath, and then compile this program:

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

public class CreateMedia {
  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(); 
      Media m = new Media(2,"VHS");
      db.create(m); 
      // Commit the transaction
      db.commit(); 
      db.close(); 
    } catch (PersistenceException e) {
      e.printStackTrace(); 
    }  
  }
}

- Listing 2: The first Castor program -

You don't get it shorter than that. Nevertheless it illustrates the basic layout of a Castor program. The program creates an instance of object Media, and stores it in a database. The Media class will be shown below.

Let's look at the program structure:

  • The JDO object is the one that creates the connections to the database. The name "mydb" refers to a database definition found in the configuration file "database.xml". We'll look into this file in a second.
  • Just like we're used to it when using JDBC we need to have a connection to the database--this is what getDatabase gives us.  
  • In order for us to query or store data in the database we must work in an open transaction. We use the begin method to start a transaction.
  • To tell Castor that an object should be stored in the database (when we commit) we must use the create method.
  • commit writes data to the database. After commit you may start a new transaction, or use...
  • close to close the database connection.

My error handling is of course only sufficient for a small test program like this. In a properly designed program you'd have to be able to close connections and maybe rollback transactions if severe errors occur. The small program above may actually throw four different exceptions.


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:
A Barebones Guide to Usability Testing
At first glance, usability testing may seem like unnecessary, or additional work. In todays budget slashed world, it is not uncommon for projects not to have the luxury of this valuable phase. This is a dangerous path to tread. Let's look at how we can incorporate usability testing into our design process.
... [more articles]

New Tutorial:
Java Certification Path API
Certificate based security forms the basis for SSL (Secure socket layer) transactions? Every year billions of transactions involving trillions of dollars are done safely using the SSL protocol. This week we'll look at the role of the Java certification path API and see how it provides a mechanism to implement certification path functionality.
... [more Tutorials]

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






Developer News

Is Adobe Targeting Microsoft's InfoPath?

Oracle Takes on Collaboration Market

DoS Flaw in Cisco Router, Switches



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.



Scrolling Text
This is a suite of three applets that displays scrolling text using an array of images. The detailed description of array of each applet is provided.
Download of the Week
DS PageFlipText
This applet displays a page-flip effect between texts. Over the animation you can also insert an image and a scroll-text.

JB User Poll
Which version of Java do you use the most?
The JavaBoutique Top 15:
1. ChompText
2. NavBar
3. DJPopMenu
4. PulseText
5. PingPong
6. 3DMaze
7. Encyclo
8. Viewer
9. AScroll2
10. Distorter
11. Jtimer
12. BMI
13. AnimLetters_anim
14. BMMenu
15. AScratchNWin
Want more? Check out our Top 100!

Refer-It
Affiliate Program and Referral Directory.
New on internet.com
Internet Tax Ban Hits Congressional Fast Track
Bills to permanently extend current moratorium on Internet access taxes move in House and Senate.

UK Texting Takes Off
More than 8 billion text messages were sent across the UK since the beginning of 2003, while traffic to U.S. mobile phone Web sites spikes 106 percent during the same time period.

Intersil Drops Wi-Fi
The maker of the PRISM line of WLAN chips is saying good-bye to Wi-Fi and divesting itself of its wireless product business. The chips go to broadband circuit maker GlobespanVirata for approximately $365 million.


The Event for Search Engine Marketing & Optimization

Jupitermedia is publisher of the internet.com and EarthWeb.com networks.
Copyright 2003 Jupitermedia Corporation All Rights Reserved.

Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.earthweb.com/
http://www.internet.com/