Work With Results Through Technology to Grow Your Business Contact Us Today

Categories: Oracle

Java for the Oracle Developer

The Oracle developer may be somewhat perplexed when first encountering JDeveloper.  Numerous terms and definitions are foreign to traditional Forms and PL/SQL Programmers.  The programmer occasionally needs to “roll your own” extended classes or even new clas ses to achieve “basic” functionality.  One feels like they are working with a complex procedural 3GL.  That’s because one is working with a complex procedural 3GL! Recommendations for the Oracle Development team that has not worked with Java gain sophisticated Java Programming expertise

Assure at least one team member has a good understanding of JDeveloper, including how to set up projects, generate libraries, define manifest files,  implement version control, Java Virtual Machines and the Java Runtime Environment (JRE)

Explore the following:  events/listeners, jtable methods, table models (particularly as related to customizing grid controls), extending existing classes, interfaces

Don’t be afraid to use Java!

Use more of the functionality of BC4J than simply mapping tables and creating views! Visit

Oracle for the Java Developer

The Java Developer who has had little or no previous experience with databases will find JDeveloper an excellent tool for learning how to build database applicatio ns.  Simple database applications can be created quickly and easily through wizards, while the tool allows experienced programmers to access the lowest levels of control.

Many developers new to databases often use the database as simply a storage location for putting and retrieving records. However, databases such as Oracle provide much, much more powerful resources for the practical JDeveloper to quickly create sophisticated applications.

Recommendations for the Java Developer Team that has not worked with Oracle:

Gain sophisticated SQL programming expertise.   There’s more to it than most utilize.

Assure at least one team member acquires a good understanding of Oracle, including how to set up tnsnames, the init.ora file, tuning approaches

Explore the fo llowing resources: database triggers, database stored procedures, optimization hints, query outlines, indexing options, virtual private databases, views, materialized views, constraints, IFS, database links to Oracle and heterogeneous databases, interMedia , database security approaches, SQL*Loader

Evaluate Oracle Enterprise Manager and similar 3rd party tools

Test your SQL in SQL*Plus first.  If it takes a long time to process there… figure out why.  There is generally a good reason why it is slow, and more often than not you can do something about it ( Creating appropriate indexes, changing your SQL, modifying ora.ini parameters such as number  of  buffers, using hints, etc )

Consider leveraging rather than replacing existing database routines such as store d procedures, constraints, sequences and triggers.  Remember that database functionality is available to all developers and all toolsets at very low levels, and is already tested and working

Don’t be afraid to use BC4J for more than mapping tables and creating views! Visit

JDeveloper for the MS Access™ Developer

You aren’t in Redmond, anymore!

At  first glance JDeveloper seems to be vastly inferior.  No reporting tool, no obvious fancy functions, no apparent instant
JPG integration!  And you have a seemingly overly complex IDE with a seemingly overly complex database back end!

For large scale, sophisticated, long lived enterprise applications, JDeveloper provides a powerful environment for the professional developer. “Overly complex”  generally means it has a host of features one doesn’t know one needs until  one is well into production and running into architectural dead ends of less sophisticated products!

If, however, MS Access serves your purpose, then be Practical and use it.  It may be the right tool for the right use in your situation.

Recommendations for the MS Access Developer:

Keep an open mind.  This is just like learning for the first time about writing Macros and then turning actual Basic Modules into a real application.  It’s a learning experience… and the more you learn, the more you learn how to take control of your application at lower and lower levels…

Stick with it. Through Pain comes understand and appreciation of  the whys of complexity

Explore BC4J in it’s entirety

If you don’t see functionality you need… search the help (it’s usually available, just not obvious), look for 3rd party components on the web, or roll your own.   And then share it with other developers through one of the various forums available.

A Word About Wizards

There are numerous Wizards that assist one is setting up projects and business components.  These wizards are useful and ease the creation of an application.   Any non-trivial application, however, will quickly require a fairly deep understanding of Java, Oracle and Business Components for Java by the developers.

Business Components for Java

East meets west through Business Components for Java.(BC4J).  For years there has been a tug of war between database and applications designers… where should rules and code be physically instantiated?    A constant tug of war… in the code.. in the database.  Both had pros and cons.

BC4J offers an alternative approach taking the best of both worlds and setting up a framework that can be deployed at multiple levels.. taking the strengths of the database layer and applying it in a structured manner to a middle tier code layer… and taking the strengths of the application code layer and applying it in a structured manner to the middle tier code layer!

A frequent question when developers first encounter JDeveloper is.. “Why use this JDeveloper instead of Competitor X”. BC4J is the strongest poker hand JDeveloper has to play in response.  To those who understand and utilize BC4J… they’ve got a royal flush!

For traditional database applications’ engineers, BC4J gives parallels t o familiar database concepts, under a framework accessible via Java:

Database Concept    BC4J Concept    Notes
Domains (rdb), user
defined types    Domains    Use these! Define “custom datatypes” and apply them to your entity object
attributes… examples:  a_social_security_number. a_state_abbreviation, a_phone_number
Tables/Views/Synonyms    Entity Objects    Remember that an entity object could be a database view that contains
dblinks in the server database.. or you can have entity objects that operate in a distributed ma nner, as well, using different connections.
Column    Entity Attribute, View
Object Attribute    The attributes can be computed and not persisted in an underlying database
Foreign/Primary Key    Associations     Can indicate cardinality!
Views    View Objects
N/A?     View Links    Master:Detail, one:many or cascading
Triggers    Entity Object Impl
methods (within the EO)
or Publish/Subscribe    Publish/Subscribe to affect changes or validations across entity objects! (
very interesting! )
Commit time validation
event     Entity’s validateEntity() method
Stored Procedures    Java Class methods
Default Values    EntityObjectImpl.create()    Create() method, using the appropriate setAttribute() methods
Constraints    In Impl SetAttributes
methods     Also EO validation rules, via Domain definitions and methods, and the
Entity validateEntity() method
Composition Association    Delete Restrict; Trigger to Parent
Primary Key Sequence (
applied via before insert
trigger)    Implemented in
method    If the database already has a trigger sequence, set the sequence attribute to
mandatory=no, refresh after insert=yes; and in the create set the sequence
attribute to an incremented negative int.  This will “fake” a sequence compatibly and avoid a network interchange.
Transactions    ApplicationModule.
Locking    Default is “pessimistic
locking”    May be slightly different that most database programmers are acquainted
with.  When read, it does not lock the record… when the record is first updated.. then the lock gets thrown. If you need to lock at the top of the transaction you can have explicit locking control through other methods.
Cursors    ScrollableRowsetAccess    Also look at DataItemViews (see Excel example)

While these are all not exact equivalents, the BC4J framework offers many extensions to traditional capabilities… such as defining one:many  metadata definitions from a view object onto a view object.  The framework also goes far, far beyond the simple table and view mappers that other IDEs generally offer.

For Database folk this is a comfortable, familiar arrangement, once the terminology and differences are understood.  For non- Database Java developers, this provides a structured framework for understanding database oriented applications design and implementation.

For large enterprise applications development, BC4J looks very, very promising over the alternatives.

Déjà vu? Do I really need BC4J?

For the traditional database applications programmer, BC4J may simply look like database capabilities duplicated in the applications coding tier.  Indeed, if one is coding against an existing database with many validation rules and business processes coded in PL/SQL stored procedures and triggers, the better part of valor may be to implement the BC4J in a reduced but compatible scope.  In the future,  one can envision migrating BC4J classes to inside the database ( or simply called from the database) and having interplay between existing PL/SQL procedures and triggers and BC4J functionality. However, the database programmer may go through the steps of:

(1)  I can do it all in the database functions quicker and easier

(2)  Wow, it sure would be nice if I could define more metadata to add business semantics to the database, and share understanding/version control with those applications folk

(3)  HEH… through BC4J and the Extensible Object oriented environment… adding business semantics to the database becomes realizable!  And applications folk can understand what I’m doing… and I can work closer to their environment!

For the traditional Java Programmer, it might look like direct JDBC calls and “in code” validations would be simpler and cheaper to implement, and that BC4J introduces too much overhead.  However, given a sufficiently sophisticated database application, the Java programmer will soon understand why the BC4J framework is a boon!  Too many  non-database programmers go through the stages of

(1)  I can do it quicker and easier through brute force coding

(2)  Hmmm… I’m generating lots of replication… and difficult… unstructured…uncoordinated….we ll, I can build tools to make it quicker,  easier and more coordinated…

(3)  Heh!  I’m trying to build what BC4J already offers, class by class, method by method… and it’s man-years ahead of what I could implement…well.. uh, maybe I should just use BC4J more completely….


Database triggers and constraints fire no matter what the source of the DML… SQL/Plus, a JDBC call, or an MS Access update.  BC4J does not have such primitive trapping unless you somehow can use database triggers to explicitly call the BC4J object methods.  If you have need to protect your database at this level, BC4J can still be used to augment this with middle or client tier validation.

While it can be envisioned that the BC4J framework could create a semantic business layer for the database (not just syntax validation! ), implementing such a model transparently and completely appears to be a ways off for most organizations.

BC4J and its integration with the application layer has improved greatly over the last couple of years, but there are still some minor tweaking that will be resolved over future releases.  For example, effective trapping of commit and rollback events in a procedural, ordered, aware manner.

BC4J is fairly “open”.  As such, the source can often be reviewed and extended by the applications programmer.. The bad news is that it is large, can appear fairly complex… and one must have a fairly significant  understanding of the

DACF layer, the Swing layer (if applicable), the BC4J layer, and the Infobus layer to be able to n egotiate all their application’s needs.  And also understand how to apply “oil to any friction” that may encountered between layers.  ( Example:  3.2 and before : DACF date formatters returning error if the application code set a date to NULL, or rollbacks resetting DACF grid control formats back to their original state.)

There are often checkboxes available to the programmer that oversimplify the actual complexity of the task.  For example, the Entity Object Attribute “Queriable” checkbox, or uppercase searching:  without indexes defined in the database to support those queries and a design that takes into account the performance cost of  maintaining those indexes, those simple checkboxes and property settings at the application level can significantly degrade the user experience. Another example is the default pessimistic locking scheme.  The programmer needs to understand the tradeoffs of the approach, which can include improved concurrency and reduced stalling.. but potentially increased failures “Another
user has updated…” in very high update environments over a smaller set of high contention records ( such as inventory
movement  in a robotic environment ), where an exclusive lock on the table at transaction start may actually improve throughput and reduce transaction commit failures.. but with greater stalling.

Whereas Stored Procedures and Triggers are usually procedural in orientation, the equivalent under BC4J may be a set of events/listener methods that all fire in parallel. In the event certain tasks must be completed before the later tasks can begin, special coding may be required to synchronize and coordinate the threads.

BC4J Framework is best implemented in structured environments which use formal design modeling.  As in any large object oriented project, centralized management of classes and methods are essential to achieving the re -usability gains and limiting a plethora of ill conceived classes and method implementations.


  • Read the BC4J Whitepapers on
  • Determine, design and implement domains at the beginning of the project
  • Understand the event/listener publish/subscribe event driven approach
  • Move applicable validation code which you may have in your client code to the appropriate BC4J class methods or functions.  Understand how to trap errors using this approach.
  • Consider Defining the BC4J classes in a separate project managed and maintained by a BC4J administrator.  This can then be used in turn by multiple projects.
  • In JDeveloper 3.2 and earlier, implement all session and rowSetInfo/attributeInfo definitions in their own class, rotating them out of any Wizard generated frame classes, for example.  This will mean that the IDE no longer will allow you to choose attributes via the property boxes for DACF controls… you will have to manage these directly in the source code.  But in the long run, on a significant application project, you will come out ahead.
  • If you run into a conceptual roadblock, or cannot find the correct method to fulfill a task, ask for help on the
  • JDeveloper forum at
  • Get it working.  Then optimize it. Performance always matters.  If one deployment approach results in unacceptable performance, try a different deployment approach.

Yes, there are bugs in the JDeveloper IDE.   Issues with bugs in the source editor can be frustrating. Remain focused on the gains brought by the BC4J framework for the long haul.  The bugs will eventually be fixed.  And the BC4J framework will only get better!  Don’t throw the baby out with the bathwater!

Some Practical Code Fragments


For the Practical JDeveloper with the goal of getting the job done quickly and effectively, the decision to use the right tool at the right time is an important one.

One could use JDeveloper to create and format an html report to a file, and then display that file to a browser, but there are numerous third party report writers that are tailored to the task that can get the job done quickly, easily and with much more powerful options out of box.

Oracle Reports  6i and Reports Server 6i are such tools.  With Reports 6i you can quickly generate complex reports.  Reports Server 6i installed on a middle tier will allow JDeveloper to directly call reports for displaying in the browser, emailing, or printing to printers accessible to the middle tier server.  Code samples follow, showing building a URL.  You’ll probably use one of the more secure methods (such as using a keyfile) of  calling reports 6i in actual usage, but this will get you started….

Build a string that defines a valid URL to request a print out of a report ( See Reports 6i server documentation ):

/* note the multiple back slashes to get past the layers */ myURLRequest.append( “http:\\\\\\ReportsServer”); myURLRequest.append(“&report=drive:/directory/”); myURLRequest.append( pReportName);
myURLRequest.append( pOtherParameters); myURLRequest.append(“&userid=”+Application1.currentReportUser); myURLRequest.append(“&destype=PRINTER&desname=\\\\PRINT_SERVER\\”); myURLRequest.append(pPrinterTarget);
if (isPostscriptPrinter)
{ myURLRequest.append(“&desformat=”+pOrientation);}

Remember that you can test the URL directly in your browser to start with, then work on the Java code. The following takes the URL built to print a report and calls Reports 6i directly

URL url = new URL ( pURL );
HttpURLConnection urlConn =(HttpURLConnection)url.openConnection();
catch ( IOException io )

Or to bring it up in Acrobat in an IE or Netscape Window:

MyURLRequest.append(“&desformat=PDF&destype=CACHE”); /* use this in your built URL */

/* The following is in a generalized mthod that takes a URL */
/* for either direct execution via http or through bringing up the command line */
/* on the client for displaying the report in PDF format.. */

if (System.getProperty(“”).equals(“Windows NT”) )
/* throw own the up arrow in front Aof the ampersand so NT */
/* command line will not barf */
posIdx = pURL.indexOf(“&”);
while ( posIdx > 0 )
tempstr = pURL.substring(0,posIdx)+”^”+pURL.substring(posIdx);
pURL = tempstr;
posIdx = pURL.indexOf(“&”,posIdx+2);
{Runtime.getRuntime().exec(“cmd  /c start “+pURL);}
catch (Exception e1) {System.out.println(e1.getMessage());  }
else /* Win95 and 98 */
try {Runtime.getRuntime().exec(“start  “+pURL);}
catch (Exception e2) {System.out.println(e2.getMessage());}

Export to Excel™

A common request of users is the ability to export the data one has retrieved to Microsoft Excel™.   The following example shows how to extract the data from a rowSetInfo to a file, and then bring up Excel:

void excel_btn_actionPerformed(ActionEvent  e)
String rowRecord = “”; PrintWriter out = null; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try
{out = new PrintWriter ( new FileOutputStream(“c:\\FileName.xls”));} catch (FileNotFoundException e2) { System.out.println(e2.toString());  } out.println(“My Column Titles\tTitle 2\tTitle3”);
/* we use DataItemView to run through all the records in the rowset */
/* we do not use simple ScrollableRowsetAccess because that will cause*/
/* rowChangeListeners to fire everywhere, while DataItemView will not*/
ScrollableRowsetAccess x = (ScrollableRowsetAccess)myRowSet.getRowsetAccess();
Object dataItem = myRowSet.getRowsetAccess();
DataItemView dview = (DataItemView)dataItem;
ArrayAccess access = dview.getView(-1);
int buffSize = x.getBufferSize();
int k = 0;
int rowCount = x.getRowCount();
for (int i=0; i<rowCount; i++)
k = i%buffSize;
/* reset my window on the world, since the dataItemView only sees a  */
/* windowed buffer of records at any point of time of the entire resultset */
if ( k==0 )
access = dview.getView(-1);
/* build the row, using tabs and getting the formatting right */
/* 1,2,6,7 are the attributes in the rowsetInfo as they appear in order */
rowRecord = (
((ImmediateAccess)access.getItemByCoordinates( new int[] { (k),1 }
((ImmediateAccess)access.getItemByCoordinates( new int[] { (k),2 }
((ImmediateAccess)access.getItemByCoordinates( new int[] { (k),6 }
((ImmediateAccess)access.getItemByCoordinates( new int[] { (k),7 }
out.println ( rowRecord );
catch ( Exception e0) {System.out.println(e0);}
/* note the doubleslash needed */
if (System.getProperty(“”).equals(“Windows NT”) )
{Runtime.getRuntime().exec(“cmd  /c start excel /e  c:\\FileName.xls”);}
catch (Exception e1) {System.out.println(e1.getMessage());  }
else /* W95 or W98 */
{Runtime.getRuntime().exec(“start  excel /e c:\\FileName.xls”);}
catch (Exception e2) {System.out.println(e2.getMessage());}

Last Words

The extent to which one uses the BC4J framework, vs rolling your own in Java or using legacy code in the Database, is dependent upon the staff training , time to implementation, ultimate design goals and the architecture of your system.  Once again, the Practical JDeveloper  whatever tools are at their disposal to accomplish the goal of implementing the stable production database application as quickly and easily as possible.

Don’t be afraid of using Java solutions or Database solutions if they are more comfortable to you and will accomplish the task quicker.  Learning how to use the other approaches can be left to later projects… there is considerable territory to cover from both directions!

Best of Luck!

Spread the Word, like or share this page, your friends will also love it and thanks for it.

About the Author

Scott Nelson is an entrepreneur, Oracle wizard, consultant, businessman, filmmaker, inventor, tinkerer. He's always been willing to approach the unapproachable, attempt the impossible, reach for the brass ring in a wild dive into the darkness of the unknown because his motto is “All you have to do is do it” Currently living the good life in southern Indiana amongst the hills and pleasant valleys of Brown County.