WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

examples.dbkona
Class query

java.lang.Object
  |
  +--examples.dbkona.query

public class query
extends java.lang.Object

This simple example shows how to connect and execute queries with dbKona. You will need to have Oracle running the DEMO database, with WebLogic jDriver for Oracle (or another Oracle JDBC driver). This example is executed from the command line, and results are displayed to standard out. For other examples of how to display query results, check the server-side Java examples that use dbKona in the examples/servlets folder.

If you don't have the Oracle DEMO database, you can use the file utils/ddl/demo.ddl to set it up.

The following section describes how to build and run the examples:

  1. Build the example
  2. Run the example
  3. Check the output

Build the example

  1. Set up your development shell as described in Setting up your environment for building and running the examples.

  2. Set your PATH to include the path to the WebLogic jDriver for Oracle DLLs. For example:
    set PATH=%PATH%;C:\bea\weblogic700\server\bin\oci817_8

  3. Set your CLASSPATH to include the path the BEA_HOME folder where the license.bea file resides. For example:
    set CLASSPATH=%CLASSPATH%;C:\bea

  4. Open query.java for editing and find the following code block:
           Properties props = new Properties();
           props.put("user",     "scott");
           props.put("password", "tiger");
           props.put("server",   "DEMO");
     
    You may need to replace these values to fit your configuration.

  5. Compile the example by executing an ant build script or a command.

Run the example

  1. Run this example by executing the following command in your development shell:

    prompt> ant  run_query

Check the Output

 Buildfile: build.xml
 
 run_query:
      [java] Starting Loading jDriver/Oracle .....
      [java] Record count = 14
      [java] Record count = 2
      [java] Record count = 2
      [java] Record count = 2
      [java] Record count = 2
      [java] Record count = 2
      [java] Record count = 2
      [java] Record count = 2
      [java] Record count = 0
      [java] Name                DB Type        Type           Length Prec Scale Null OK
      [java] EMPNO               NUMBER         SHORT          4      4    0     no
      [java] ENAME               VARCHAR2       STRING         10     0    0     yes
      [java] JOB                 VARCHAR2       STRING         9      0    0     yes
      [java] MGR                 NUMBER         SHORT          4      4    0     yes
      [java] HIREDATE            DATE           TIMESTAMP      9      0    0     yes
      [java] SAL                 NUMBER         FLOAT          9      7    2     yes
      [java] COMM                NUMBER         FLOAT          9      7    2     yes
      [java] DEPTNO              NUMBER         BYTE           2      2    0     yes
      [java]
      [java] 7369 - SMITH - 1980-12-17 00:00:00.0
      [java] 7499 - ALLEN - 1981-02-20 00:00:00.0
      [java] 7521 - WARD - 1981-02-22 00:00:00.0
      [java] 7566 - JONES - 1981-04-02 00:00:00.0
      [java] 7654 - MARTIN - 1981-09-28 00:00:00.0
      [java] 7698 - BLAKE - 1981-05-01 00:00:00.0
      [java] 7782 - CLARK - 1981-06-09 00:00:00.0
      [java] 7788 - SCOTT - 1987-04-19 00:00:00.0
      [java] 7839 - KING - 1981-11-17 00:00:00.0
      [java] 7844 - TURNER - 1981-09-08 00:00:00.0
      [java] 7876 - ADAMS - 1987-05-23 00:00:00.0
      [java] 7900 - JAMES - 1981-12-03 00:00:00.0
      [java] 7902 - FORD - 1981-12-03 00:00:00.0
      [java] 7934 - MILLER - 1982-01-23 00:00:00.0
 
 BUILD SUCCESSFUL
  

Author:
Copyright (c) 1996-2002 by BEA Systems, Inc. All Rights Reserved.

Constructor Summary
query()
           
 
Method Summary
static void main(java.lang.String[] argv)
          Here the JDBC connection is set up and created.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

query

public query()
Method Detail

main

public static void main(java.lang.String[] argv)
Here the JDBC connection is set up and created. A JDBC Statement is executed, and its resulting data is used to construct a dbKona QueryDataSet from the "emp" table in the Oracle DEMO database.

A QueryDataSet simplifies the client-side management of JDBC results by providing the infrastructure of a memory cache. QueryDataSets also allow records to be fetched incrementally. dbKona also provides methods associated with DataSets to automatically generate SQL. A QueryDataSet can be constructed with or without a JDBC ResultSet, which is shown in this method.

After working with the DataSet, we close it, as well as the JDBC ResultSet and the Statement used to execute the query.


Documentation is available at
http://e-docs.bea.com/wls/docs70

Copyright © 2002 BEA Systems, Inc. All Rights Reserved.