Java Programming with Oracle SQLJ: Contexts and Multithreading
O'Reilly Book Excerpts: Java Programming with Oracle SQLJ

Contexts and Multithreading

by Jason Price

This excerpt is Chapter 8 from Java Programming with Oracle SQLJ, published in August 2001 by O'Reilly.

There are two important objects used in SQLJ that affect the execution of database operations: connection contexts and execution contexts. Connection contexts are used to connect to a database. All embedded SQL statements within a SQLJ program run in a connection context. Connection contexts make it possible to create multiple connections to a database or to connect to more than one database at a time. An execution context is used to hold the number of rows affected by a SQL operation, along with any warnings generated by the database. Execution contexts are used to control certain aspects of how a SQL statement is executed. For example, you can use an execution context to control the timeout period after which a SQL operation is abandoned.

A multithreaded program is one that is able to carry out several tasks in parallel using Java threads. As you will see in this chapter, execution contexts are very important when writing a multithreaded SQLJ program.

In this chapter:

Connection Contexts

Multiple Database Connections

Specifying the connection context to use
Understanding transactions and multiple connection contexts
Making connections to multiple databases
Closing connection contexts

Example Program: ContextExample1.sqlj

Execution Contexts

The Default Execution Context

Execution Context Methods

getWarnings( )
getUpdateCount( )
setQueryTimeout( )
getQueryTimeout( )
setMaxRows( )
getMaxRows( )

Creating a New Execution Context

Specifying an Execution Context

Example Program: ContextExample2.sqlj

Multithreaded SQL J Programs

Designing a Multithreaded SQL J Program

Example Program: MultithreadedExample1.sqlj

The MultithreadedExample1 class
The main( ) method
The run( ) method
Program output


[1] [2] [3] [4] [5] Next

Close    To Top
  • Prev Article-Java:
  • Next Article-Java:
  • Now: Tutorial for Web and Software Design > Java > JDOnJDBCnSQLJ > Java Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction