Index   Search   Add FAQ   Ask Question  

Java FAQ (JServer, JDBC and JSQL)

$Date: 10-Oct-1999 $
$Revision: 1.11 $
$Author: Frank Naudé $

An all time dumb question:
    Person A. Duh... in what language should we program?
    Person B. Wake up and smell the Java you IDIOT!!!

Topics

  • What is JDBC and what is it good for?
  • What is JSQL and what is it good for?
  • What is the diference between a program and an applet?
  • How does one use the Oracle JDBC Thin Driver?
  • How does one use the Oracle OCI Drivers?
  • Where can I get more info about JDBC and JSQL?

  • Return to Oracle FAQ Index

    What is JDBC and what is it good for?

    JDBC is a set of classes and interfaces written in Java to allow other Java programs to send SQL statements to a relational database management system.

    Oracle provides three categories of JDBC drivers:

    Oracle's JDBC Thin driver is a Type 4 driver that uses Java sockets to connect directly to Oracle. It provides its own implementation of a TCP/IP version of Oracle's SQL*Net. Because it is 100% Java, this driver is platform independent and can also run from a Web Browser.

    The Oracle Call Interface (OCI) is an application programming interface to Oracle databases. It consists of a library of C language routines to allow C programs (or programs written in other third generation languages) to send SQL statements to the database and interact with it in other ways.

    Oracle's JDBC OCI drivers are Type 2 JDBC drivers. They provide an implementation of the JDBC interfaces that uses the OCI to interact with an Oracle database. You must use a JDBC OCI driver appropriate to your Oracle client installation. The OCI driver works through either SQL*Net or Net8.

    Either of these client versions can access Oracle7 or Oracle8 servers.

    The JDBC OCI drivers allow you to call the OCI directly from Java, thereby providing a high degree of compatibility with a specific Version of Oracle. Because they use native methods, they are platform specific.

    Oracle's JDBC KBPR driver is used equivalent to the server side OCI driver. The KBRP driver is mainly used for writing Java stored procedures and triggers.

    All three drivers support the same syntax and API's. Oracle needs three drivers to support different deployment options. Looking at source code, they will only differ in the way you connect to the database. Remember, you must use a JDBC version that matches your Java Development Kit.

  • Back to top of file

  • What is JSQL and what is it good for?

    JSQL is an ANSI standard way of interfacing SQL and Java. It provides a Java precompiler that translates JSQL call to JDBC calls. The idea is similar to that of other Oracle Precompilers.

    SQLJ is more concise and thus easier to write than JDBC, and provides compile-time schema validation and syntax checking for easier debugging. SQLJ reads input either from a SQLJ file, or a Java source file in which SQLJ statements are embedded. The SQLJ precompiler translates the SQLJ statements into their equivalent JDBC calls. SQLJ supports static SQL.

  • Back to top of file

  • What is the diference between a program and an applet?

    Applets:

    Applets do not live in a page as is commonly perceived. Applets are actually Java classes identified via HyperText Markup Langauge (HTML) tags within Web documents, it is these HTML tags that are embedded within Web documents. Java Applets are loaded from Web Servers somewhere on the Internet or within your corporate Intranet or Extranet.

    Applications:

    Java applications fit the traditional application model in the sense that they are executed from a command line and need to be installed on, or migrated to, each application host machine and then executed within that machine's JVM using the following command line construct:

    Sample Java Application:

            /**
             * The HelloWorldApp class implements an application that
             * simply displays "Hello World!" to the standard output.
             */
            class HelloWorldApp {
                    public static void main(String[] args) {
                            System.out.println("Hello World!"); //Display the string.
                    }
            }
    
    Sample Java Applet:
            import java.applet.Applet;
            import java.awt.Graphics;
    
            public class HelloWorld extends Applet {
                    public void paint(Graphics g) {
                            g.drawString("Hello world!", 50, 25);
                    }
            }
    
  • Back to top of file

  • How does one use the Oracle JDBC Thin Driver?

    The the JDBC thin driver provides the only way to access Oracle from the Web (applets). It is smaller and faster than the OCI drivers, and doesn't require a pre-installed version of the JDBC drivers.
    import java.sql.*;
    class dbAccess {
      public static void main (String args []) throws SQLException
      {
            DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
    
            Connection conn = DriverManager.getConnection
                 ("jdbc:oracle:thin:@qit-uq-cbiw:1526:orcl", "scott", "tiger");
                                 // @machineName:port:SID,   userid,  password
    
            Statement stmt = conn.createStatement();
            ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
            while (rset.next())
                  System.out.println (rset.getString(1));   // Print col 1
            stmt.close();
      }
    }
    
  • Back to top of file

  • How does one use the Oracle OCI Drivers?

    One must have SQL*Net installed and working before attempting to use the OCI drivers.
    import java.sql.*;
    class dbAccess {
      public static void main (String args []) throws SQLException
      {
            try {
                  Class.forName ("oracle.jdbc.driver.OracleDriver");
            } catch (ClassNotFoundException e) {
                  e.printStackTrace();
            }
    
            Connection conn = DriverManager.getConnection
                 ("jdbc:oracle:oci8:@qit-uq-cbiw_orcl", "scott", "tiger");
                         // or oci7 @TNSNames_Entry,    userid,  password
    
            Statement stmt = conn.createStatement();
            ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
            while (rset.next())
                  System.out.println (rset.getString(1));   // Print col 1
            stmt.close();
      }
    }
    
  • Back to top of file

  • Where can I get more info about JDBC and JSQL?

  • Back to top of file

  • General: Home | Index | Preamble | Glossary | OraCorp | Papers | Fun | News | Events | Y2000 | Books | Links | Forums
    Products: SQL | Plus | Loader | PL/SQL | PreComp | OPO | OMO | OO4OLE | DBA | PQO | PSO | OCO | Net | ODBC | WebServer | Des2k | Dev2k
    Systems: MVS | Unix | Windows | WindowsNT | NetWare | VMS